Creating Graphical User Interfaces |
Sharing Data Between Callbacks
This topic describes the process for sharing data between callbacks in a GUI. Subsequent topics, Adding Code to the Opening Function and Adding Code to the Callbacks, contain examples.
You can share data between callbacks by storing the data in the MATLAB handles
structure. All components in a GUI share the same handles
structure. It is passed as an input argument to all callbacks generated by GUIDE.
For example, to store data contained in vector X
in the handles
structure, you
handles
structure where you want to store the data, for example, handles.my_data
handles
structure and set it equal to X
with the following statement:
handles
structure with the guidata
function:
Here, hObject
is the handle to the component object that executes the callback. The component's object handle is passed as the input argument, hObject
, to each of its callbacks that is generated by GUIDE.
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
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.
Opening the GUI M-File | Adding Code to the Opening Function |
© 1994-2005 The MathWorks, Inc.