Specifications

Saving the GUI
3-29
Saving the GUI
The FIG-file that you create with the Layout Editor enables MATLAB to
reconstruct your GUI when it is deployed. Generally, a functional GUI consists
of two components:
A FIG-file – containing a description of the GUI
An M-file – containing the program that controls the GUI once it is deployed
FIG-Files
FIG-files (filename.fig) are binary files created as a result of saving a figure
with the
hgsave command or using Save from the Layout Editor’s File menu.
FIG-files replace the MAT-file/M-file combination that was previously used to
save figures.
What a FIG-File Contains
A FIG-file contains a serialized figure object. That is, a complete description of
the figure object and all of its children is saved in the file. This enables
MATLAB to reconstruct the figure and all of its children when you open the
file. All of the objects property values are set to the values they were saved with
when the figure is recreated.
By default, FIG-files do not save the default figure toolbars and menus,
although you can save these elements using the
hgsave and hgload commands.
Handle Remapping
One of the most useful aspects of FIG-files is the fact that object handles saved,
for example, in a
UserData property are remapped to the newly created,
equivalent object.
For example, suppose you have created a GUI that uses three radio buttons.
Whenever a user selects one of the radio buttons, its callback routine must
check the state of the other radio buttons and set them to
off (as this is the
standard behavior of radio buttons). To avoid having to search for the handles
of the other radio buttons (with
findobj), you could save these handles in a
structure in the
UserData property of each object.
When MATLAB reconstructs the figure and children (that is, deploys your
GUI), the handles of the equivalent new objects are assigned to a structure
with the same name and fields as in the original objects.