User`s guide

13 Manage Application-Defined Data
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
When you place nested functions in a GUI code file, they enable callback
functions to share data freely w ithout it having to be passed a s arguments:
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 access to the data and
the component handles because they are defined at a higher level. Using this
approach can eliminate the need for storing
UserData, application data, or
GUI Data in many instances.
Note For the rules and restrictions that apply to using nested functions,
see “Nested Functions”.
13-4