
8 Programming the GUI
8-6
GUI M-File Structure
The GUI M-file that GUIDE generates is a function file. The name of the main
function is the same as the name of the M-file. For example, if the name of the
M-file is
mygui.m, then the name of the main function is mygui. Each callback
in the file is a subfunction of the main function.
When GUIDE generates an M-file, it automatically includes templates for the
most commonly used callbacks for each component. The M-file also contains
initialization code, as well as an opening function callback and an output
function callback. You must add code to the component callbacks for your GUI
to work as you want. You may also want to add code to the opening function
callback and the output function callback. The major sections of the GUI M-file
are ordered as shown in the following table.
Section Description
Comments Displayed at the command line in response to the
help command. Edit these as necessary for your
GUI.
Initialization GUIDE initialization tasks. Do not edit this code.
Opening function Performs your initialization tasks before the user
has access to the GUI.
Output function Returns outputs to the MATLAB command line
after the opening function returns control and
before control returns to the command line.
Component and
figure callbacks
Control the behavior of the GUI figure and of
individual components. MATLAB calls a callback
in response to a particular event for a component
or for the figure itself.
Komentáře k této Příručce