
Mechanisms for Managing Data
9-3
GUI data provides application developers with a convenient interface to a
figure’s application data:
• You do not need to create and maintain a hard-coded name for the data
throughout your source code.
• You can access the data from within a callback routine using the component’s
handle, without having to find the figure handle. For GUIDE users, the
object handle is automatically passed to each callback as
hObject.
GUI Data in GUIDE
GUIDE automatically uses guidata to create and maintain the handles
structure. This structure is automatically passed as an argument to every
callback. The
handles structure contains the handles of all components in the
GUI.
In a GUI created using GUIDE, you cannot use
guidata to manage any
variable other than the
handles structure. If you do, you may overwrite the
handles structure and your GUI will not work. If you want to use GUI data to
share application-defined data among callbacks, you must save the data in
fields that you add to the
handles structure.
Note that the GUIDE templates use the
handles structure to store
application-defined data. See “Selecting a GUI Template” on page 6-5 for
information about the templates.
Note For more information, see “The Handles Structure” on page 8-13.
Adding Fields to the handles Structure
To add a field to the handles structure, which is passed as an argument to
every callback in GUIDE.
1 Assign a value to the new field. This adds the field to the structure. For
example
handles.number_errors = 0;
adds the field number_errors to the structure handles and sets it to 0.
Kommentare zu diesen Handbüchern