MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Bedienungsanleitung Seite 218

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 330
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 217
9 Managing Application-Defined Data
9-6
1 Use getappdata to retrieve the structure.
From the example in the previous topic, the name of the application data
structure is
mydata. It is associated with the figure whose Tag is figure1.
Since the
handles structure is passed to every callback, the code can specify
the figure’s handle as
handles.figure1.
function mygui_pushbutton1(hObject, eventdata, handles)
matrices = getappdata(handles.figure1,'mydata');
2 Create a new field and assign it a value. For example
matrices.randn_50 = randn(50);
adds the field randn_50 to the matrices structure and sets it to a 50-by-50
matrix of normally distributed random numbers.
3 Use setappdata to save the data. This example uses setappdata to save the
matrices structure as the application data structure mydata.
setappdata(hObject,'mydata',matrices);
UserData Property
All GUI components, including menus, and the figure have a UserData
property. You can assign any valid MATLAB value to the
UserData property.
To retrieve the data, a callback must know the handle of the component with
which the data is associated.
1 In this example, an edit text stores the user-entered string in its UserData
property.
function mygui_edittext1(hObject, eventdata, handles)
mystring = get(hObject,'String');
set(hObject,'UserData',mystring);
2 A push button retrieves the string from the edit text UserData property. The
callback uses the
handles structure and the edit text Tag property,
edittext1, to specify the edit text handle.
function mygui_pushbutton1(hObject, eventdata, handles)
string = get(handles.edittext1,'UserData');
Seitenansicht 217
1 2 ... 213 214 215 216 217 218 219 220 221 222 223 ... 329 330

Kommentare zu diesen Handbüchern

Keine Kommentare