MATLAB Creating Graphical User Interfaces
Callback Property User Action Components That Use This Property WindowButtonU pFcn End user releases a mouse button. figure Wind ...
b = uicontrol('Style','pushbutton','Callback',@pushbutton_callback); Here is the function definition for pushbutton_callback: fu ...
arguments as described in “Specify a Function Handle” on page 10-7. However, you can define additional inputs in your function d ...
The character vector, 'plot(rand(20,3))', is a valid command, and MATLAB evaluates it when the user clicks the button. If the ch ...
Manage Application-Defined Data 11 ...
Share Data Among Callbacks In this section... “Overview of Data Sharing Techniques” on page 11-2 “Store Data in UserData or Othe ...
Method Description Requirements and Trade-Offs “Create Nested Callback Functions (Programmatic Apps)” on page 11-12 Nest your ca ...
If your code does not have direct access to a component, use the findobj function to search for that component. If the search is ...
When the user moves the slider, the slider_callback uses these commands to store data in a structure: data = struct('val',sval, ...
data = struct('val',0,'diffMax',1); set(handles.slider1,'UserData',data); After you add the commands, myslider_OpeningFcn looks ...
% hObject handle to slider1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure wi ...
This code uses the handles structure to access the slider. The command, data = get(handles.slider1,'UserData'), gets the slider’ ...
'String','Display Values',... 'Callback',@button_callback); end function slider_callback(hObject,eventdata) diffMax = hObject.Ma ...
diffval = getappdata(hObject.Parent,'difference') retrieve the difference value from the figure. Share Application Data in GUI ...
setappdata(handles.figure1,'difference',1); % Update handles structure guidata(hObject, handles); % UIWAIT makes junk wait for u ...
% Retrieve application data currentval = getappdata(handles.figure1,'slidervalue'); diffval = getappdata(handles.figure1,'differ ...
'Callback',@button_callback); function slider_callback(hObject,eventdata) sval = hObject.Value; diffMax = hObject.Max - sval; % ...
data = guidata(object_handle); The component you specify to store the data does not need to be the same component that you use t ...
% maxval = get(hObject,'Max'); % data.diffMax = maxval - data.val; guidata(hObject,data); end function button_callback(hObject,e ...
guidata(hObject,handles); end GUIDE Example: Share Slider Data Using guidata Here is a prebuilt GUIDE app that uses the guidata ...
«
12
13
14
15
16
17
18
19
20
21
»
Free download pdf