User`s guide
Ways to Manage Data in a Programmatic GUI
automatically passed to each callback as hObject. S ee “Specify Callbacks in
Function Calls” on page 12-11 for m ore information.
Because there can be only one GUI data variable a nd it is associated with the
figure, you do not need to create a nd maintain a hard-coded n ame for the
data throughout your source code.
Note GUIDE uses GUI data to store its handles structure, and includes
it as an argument (called
handles) in every callback . Programmatic G UI
callbacks do not include GUI Data, but any callback function can access
it from its component’s handle (
hObject, the first callback argument). If
GUIDE originally created your GUI, see “Changing GUI D ata in a Code File
Generated by GUIDE” on page 9-9.
Create and Update GUI Data
1 Create a structure and add to it the fields you want. For example,
mydata.iteration_counter = 0;
mydata.number_errors = 0;
2 Save the structure as GUI data. MATLAB software associates GUI data
with the figure, but you can use the handle of any component in the figure
to retrieve or save it.
guidata(figurehandle,mydata);
3 To change GUI data from a callback, get a copy of the structure, update
the desired field, and then save the GUI data.
mydata = guidata(hObject); % Get the GUI data.
mydata.iteration_counter = myda ta.iteration_counter +1;
guidata(hObject,mydata); % Save th e GUI data.
13-9