Specifications
Programming the GUI
2-19
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” on page 2-20 and
“Adding Code to the Callbacks” on page 2-22, 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
1 Choose a name for the field of the handles structure where you want to store
the data, for example,
handles.my_data
2 Add the field to the handles structure and set it equal to X with the following
statement:
handles.my_data = X;
3 Save the handles structure with the guidata function:
guidata(hObject,handles)
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.