User`s guide

13 Manage Application-Defined Data
Note To use hObject, you must specify a component’s callback properties
as function handles. When you do, the component handle is automatically
passed to e ach callback as
hObject. See “Specify Callbacks in Function
Calls” on page 12-11 for more inform ation.
Add Fields to a GUI Data Structure
To add a field to a GUI data structure:
1 Get a copy of the structure with a command similar to the following
where
hObject is the handle of the component for which the callback w as
triggered.
mydata = guidata(hObject)
2 Assign a value to the new field. This adds the field to the structure. For
example,
mydata.iteration_state = 0;
adds the field i tera tion_state to the structure m ydata and sets it to 0.
3 Use the following com mand to save the data.
guidata(hObject,mydata)
where hObject is the handle of the component for which the callback was
triggered. MATLAB software associates a new copy of the
mydata structure
with the component’s parent figure.
See “Share Data with GUI Data” on page 13-21 for a complete example.
13-10