Specifications

2 Creating a GUI
2-20
Note To save any changes that you make to the handles structure, you must
use the command
guidata(hObject,handles). It is not sufficient to just set
the value of a handles field.
To retrieve
X in another callback, use the command
X = handles.my_data;
You can access the data in the handles structure in any callback because
hObject and handles are input arguments for all the callbacks generated by
GUIDE.
For more detailed information on the
handles structure, see “Managing GUI
Data with the Handles Structure” on page 4-26.
Adding Code to the Opening Function
The Opening Function
The opening function is the first callback in every GUI M-file. You can use it to
perform tasks that need to be done before the user has access to the GUI, for
example, to create data or to read data from an external source.The code in the
opening function is executed just before the GUI is made visible to the user, but
after all the components have been created.
In this example, you add code that creates three data sets in the opening
function, using the MATLAB functions
peaks, membrane, and sinc.
Note that GUIDE names the opening function with the name of the M-file
prefixed to
_OpeningFcn. In this example, the M-file is named simple_gui.m,
so that the opening function is named
simple_gui_OpeningFcn.
For more information about the opening function see “Opening Function” on
page 4-4.
Adding the Code
To create data for the GUI to plot, add the following code to the opening
function immediately after the comments following the function declaration.
% --- Executes just before simple_gui is made visible.
function simple_gui_OpeningFcn(hObject, eventdata, handles, varargin)