Creating Graphical User Interfaces |
Sharing Data Between Callbacks
You can share data between callbacks by storing it in the MATLAB handles
structure. For example, to store data contained in a vector X
in the handles
structure, you
handles
structure where you want to store the data, for example, handles.my_data
X
with the following command:
handles
structure with the guidata
function:
Here, hObject
is the handle to the object that executes the callback.
Note
To save any changes that you make to the handles structure, you must add the command guidata(hObject, handles) following the code that implements the changes.
|
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
Opening Function | Adding Code to the Opening Function |