Specifications
Programming the GUI
2-17
Programming the GUI
After laying out the GUI and setting component properties, the next step is to
program it. This section explains how to do that. The section covers
• “Creating the GUI M-File” on page 2-17
• “Opening the GUI M-File” on page 2-17
• “Sharing Data Between Callbacks” on page 2-19
• “Adding Code to the Opening Function” on page 2-20
• “Adding Code to the Callbacks” on page 2-22
• “Using the Object Browser to Identify Callbacks” on page 2-24
Creating the GUI M-File
When you first save or run the GUI, GUIDE generates a function M-file that
contains the most commonly used callbacks for each component. It also
contains some initialization code, an opening function callback, and an output
function callback. Each callback is a subfunction that initially consists of a
framework that contains just a function definition. You must add code to the
callbacks to make them work.
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.
After GUIDE generates the M-file, it opens the
Save GUI as dialog. Type a
name in the
File name field. GUIDE assigns the same name to FIG-file and
the M-file. When you click
Save, GUIDE saves the M-file and opens it in the
M-file Editor. If you are building the GUI in this example, use the filename
simple_gui.
For more information, see “Understanding the GUI M-File” on page 4-2.
Opening the GUI M-File
In this section you add code to the callbacks for the three push buttons and the
pop-up menu.
Once GUIDE has created the M-file, you can open it in the MATLAB editor by
clicking the M-file Editor icon on the toolbar. In the editor, you can move the