User`s guide
9 Managing and Sh aring Application Data in GUIDE
• Nested Functions — Share variables defined at a higher level and call
one another when called function is below above, or a sibling of the caller.
• UserData Property — A MATLAB workspace variable that you assign to
GUI components and retrieve like any other property.
• Application Data — Provides a way f or applications to save and retrieve
data associated with a specified object. F or a GUI, this is usually the GUI
figure, but it can also be any component. The data is stored as name/value
pairs. Application data enables you to create what are essentially
user-defined properties for an object.
• GUI Data —Usesthe
guidata function to manage GUI data. This
function can store a single variable as GUI data in a MAT LAB structure,
which in GUIDE is called the handles structure. Y ou use the function to
retrieve the handles structure, as well as to update it.
You can compare the three approaches applied to a simple working G UI in
“Examples of Sharing Data Among a GUI’s C allbacks” on page 9-10.
Nested Functions
Nested functions enable callback functions to share data freely without
requiring it to be passed as arguments, and helping you to:
1 Construct components, define variables, and generate data in the
initialization segm ent of your code.
2 Nest the GUI callbacks and utility functions at a level below the
initialization.
The callbacks and utility functions automatically have acces s to the data
and the component handles because they are defined at a higher level. You
can often use this approach to avoid storing
UserData, a pplication data, or
GUIdata.
Note For the rules and restrictions that apply to using nested functions,
see “Nested Functions”.
9-4