
3 Creating a GUI Programmatically
3-6
Creating a GUI M-File
Start by creating an M-file for the example GUI.
1 At the MATLAB prompt, type edit. MATLAB opens the editor.
2 Type or copy the following statement into the editor. This function
statement is the first line in the file.
function simple_gui
3 Add these comments to the M-file following the function statement. They are
displayed at the command line in response to the
help command. They must
be followed by a blank line.
% SIMPLE_GUI Select a data set from the pop-up menu, then
% click one of the plot-type push buttons. Clicking the button
% plots the selected data in the axes.
(Leave a blank line here)
4 Add an end statement at the end of the file. This end statement matches the
function statement. Your file now looks like this.
function simple_gui_test
% SIMPLE_GUI Select a data set from the pop-up menu, then
% click one of the plot-type push buttons. Clicking the button
% plots the selected data in the axes.
end
Note You need the end statement because the example is written using
nested functions. For information about using nested functions, see Nested
Functions in the MATLAB documentation.
5 Save the file in your current directory or at a location that is on your
MATLAB path.
The next section, “Laying Out a Simple GUI” on page 3-7, shows you how to add
components to your GUI.
Comentarios a estos manuales