Creating Graphical User Interfaces |
GUIDE M-Files and FIG-Files
GUIDE automatically generates two files for each GUI:
Note that if your GUI includes ActiveX components, GUIDE also generates a file for each ActiveX component. See ActiveX Controls for more information.
This topic discusses the following:
GUI File Creation
GUIDE creates the FIG-file and M-file the first time you save or run the GUI. You can save a GUI by selecting Save or Save as from the File menu, or by clicking the Save icon on the toolbar. You can run the GUI by selecting Run from the Tools menu or by clicking the Run icon on the toolbar. If you run the GUI without having saved it, GUIDE prompts you to save it.
When you save a GUI, GUIDE assigns the name you specify for the FIG-file to both the FIG-file and the M-file, for example, mygui.fig
and mygui.m
. When you click Save in the file-save dialog box, GUIDE saves both the FIG-file and the M-file, and then opens the M-file in the M-file Editor.
GUI M-File Structure
The GUIDE GUI M-file is a function file. The name of the main function is the same as the name of the M-file. 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. It also contains some 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.
Adding Callbacks to an Existing GUI M-File
Within GUIDE, you can add a callback subfunction to the GUI M-file in one of two ways:
Note In either case, if you select a callback that already exists in the GUI M-file, GUIDE opens the M-file for editing at the callback you select. |
Changing the Name of Your GUI
The name of your GUI is the same as the name of its FIG-file and M-file. To change the name of your GUI, you must change both these file names.
In the GUIDE Layout Editor File menu, use Save As to rename the GUI FIG-file. In response, GUIDE renames both the FIG-file and the M-file. GUIDE also updates the callback properties with the new file name, as well as all instances of the file name in the body of the M-file.
Converting a GUI to a Single M-File
You can convert a GUI that was created as a FIG-file and an M-file using GUIDE to a single M-file that does not require a FIG-file. This enables you to
Note If the GUI contains a container component such as a panel or button group, you will not be able to run it in MATLAB versions earlier than 7.0. |
You can perform this conversion by exporting your GUI using the following steps:
_export
appended.
GUI Files | Files for Programmatically Created GUIs |
© 1994-2005 The MathWorks, Inc.