- diffval = getappdata(hObject.Parent,'difference') retrieve the
difference value from the figure.
Share Application Data in GUIDE Apps
To set up a GUIDE app for sharing application data, perform these steps:
(^1) In the Command Window, type guide.
2 In the GUIDE Quick Start dialog box, select Blank GUI (Default). Then, click OK.
(^3) Display the names of the UI components in the component palette:
a Select File > Preferences > GUIDE.
b Select Show names in component palette.
c Click OK.
4 Select the push button tool from the component palette at the left side of the Layout
Editor and drag it into the layout area.
(^5) Select the slider tool from the component palette at the left side of the Layout Editor
and drag it into the layout area.
(^6) Select File > Save. Save the UI as myslider.fig. MATLAB opens the code file in
the Editor.
(^7) Set the initial value of the application data in the opening function,
myslider_OpeningFcn. This function executes just before the UI is visible to users.
In myslider_OpeningFcn, insert these commands immediately after the command,
handles.output = hObject.
setappdata(handles.figure1,'slidervalue',0);
setappdata(handles.figure1,'difference',1);
After you add the commands, myslider_OpeningFcn looks like this.
function myslider_OpeningFcn(hObject,eventdata,handles,varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to junk (see VARARGIN)
% Choose default command line output for junk
handles.output = hObject;
setappdata(handles.figure1,'slidervalue',0);
11 Manage Application-Defined Data