MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Uživatelský manuál Strana 222

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 330
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 221
9 Managing Application-Defined Data
9-10
functions setappdata, getappdata, isappdata, and rmappdata to manage
application data.
See “Application Data” on page 9-4 for more information about application
data.
Application Data Example: Passing Data Between a Slider and an Edit Text
Box
The previous topic, “GUI Data Example: Passing Data Between a Slider and an
Edit Text Box” on page 9-7, used GUI data to initialize and maintain an error
counter. This example shows you how to do the same thing using application
data. Refer to the previous topic for details of the example.
1 Define the error counter in the opening function. Add the following code to
the opening function. This code first creates a structure
slider_data, then
assigns it to the named application data
slider. Because this code appears
in the opening function, using
hObject associates the application data with
the figure.
slider_data.number_errors = 0;
setappdata(hObject,'slider',slider_data);
2 Set the edit text value from the slider Callback callback. Add this statement
to the slider
Callback.
set(handles.edit1,'String',...
num2str(get(handles.slider1,'Value')));
3 Set the slider value from the edit text Callback callback. Add this code to
the edit text
Callback. It assumes the figure’s Tag property is figure1.
To update the number or errors, the code must first retrieve the named
application data
slider, then increment the count. It then saves the
application data and displays the new error count.
val = str2double(get(hObject,'String'));
% Determine whether val is a number between 0 and 1
if isnumeric(val) & length(val)==1 & ...
val >= get(handles.slider1,'Min') & ...
val <= get(handles.slider1,'Max')
set(handles.slider1,'Value',val);
else
Zobrazit stránku 221
1 2 ... 217 218 219 220 221 222 223 224 225 226 227 ... 329 330

Komentáře k této Příručce

Žádné komentáře