Specifications

4 Programming GUIs
4-26
Managing GUI Data with the Handles Structure
GUIDE provides a mechanism, called the handles structure, for storing and
retrieving shared data using the same structure that contains the GUI
component handles. The
handles structure, which contains the handles of all
the components in the GUI, is passed to each callback in the GUI M-file.
Therefore, this structure is useful for saving any shared data. The following
example illustrates this technique.
If you are not familiar with MATLAB structures, see Structures for more
information.
This section covers the following topics:
“Example: Passing Data Between Callbacks” on page 4-26
“Application Data” on page 4-29
Example: Passing Data Between Callbacks
This example demonstrates how to use the handles structure to pass data
between callbacks. The example passes data between a slider and an editable
text box in the following way:
When a user moves the slider, the text box displays the slider’s current value.
When a user types a value into the text box, the slider updates to this value.
If a user enters a value in the text box that is out of range for the slider —
that is, a value that is not between 0 an 1 — the application returns a
message indicating how many times he has entered an erroneous value.
The following figure shows the GUI with a static text field above the edit text
box.