User`s guide

9 Managing and Sh aring Application Data in GUIDE
means while it is currently running, its internal state might not need to be
initialized again. One way to do that is to set a flag and store it in the handles
structure. The opening function can test for the existence of the flag, and
perform initialization operations only if the flag does not exist. The following
code snippet illustrates this pattern:
function mygui_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 v ersion of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to spingui (see VARARGIN)
% Check whether initialization has already been performed
if ~isfield(handle s,'initialized')
% Flag not present, so create and store it
handles.initialized = true;
guidata(hObject,handles)
% perform initialization; it w ill only happen o nce.
initialize_mygui() % Insert code or function call here
end
...
Examples of Sharing Data Among a GUI’s Callbacks
“Introduction” on page 9-10
“Sharing Data with UserData” on page 9-11
“Sharing Data with Application Data” on page 9-14
“Sharing D a ta with GUI Data” on page 9-17
Introduction
The following examples illustrate the differences among three methods of
sharing data between slider and edit text G U I components. It contains a
slider and an edit text component as shown in the following figure. A static
text component instructs the user to enter a value in the edit text or click the
slider. W hen the user enters an invalid value, the edit text field displays
an error message.
9-10