MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Manuel d'utilisateur Page 434

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 500
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 433
12 Manage Application-Defined Data
12-6
the slider position. To see how it works, copy and paste this code into an editor and run
it.
function my_slider()
hfig = figure();
data = struct('val',0,'diffMax',1);
slider = uicontrol('Parent', hfig,'Style','slider',...
'Units','normalized',...
'Position',[0.3 0.5 0.4 0.1],...
'Tag','slider1',...
'Callback',@slider_callback);
button = uicontrol('Parent', hfig,'Style','pushbutton',...
'Units','normalized',...
'Position',[0.4 0.3 0.2 0.1],...
'String','Display Difference',...
'Callback',@button_callback);
function slider_callback(hObject,eventdata)
sval = hObject.Value;
diffMax = hObject.Max - sval;
data.val = sval;
data.diffMax = diffMax;
end
function button_callback(hObject,eventdata)
display([data.val data.diffMax]);
end
end
The main function defines a struct array called data. When the user moves the slider,
the slider_callback function updates the val and diffMax fields of the data
structure. When the end user clicks the push button, the button_callback function
displays the values stored in data.
Note: Nested functions are not recommended for GUIDE UIs.
Store Data Using the guidata Function
The guidata function provides a way to share data with the figure window. You can
store or retrieve the your data in any callback through the hObject component. This
means that, unlike working with UserData or application data, you do not have to
Vue de la page 433
1 2 ... 429 430 431 432 433 434 435 436 437 438 439 ... 499 500

Commentaires sur ces manuels

Pas de commentaire