User`s guide

10 Examples of GUIDE GUIs
str = get(hObject,'String');
state = find(strcmp(str,handles .Strings));
set(hObject,'String',handles.String s{3-state});
The find function returns the index of the string that matches the button’s
current label. The call to
set switches the label to the alternative string. If
state is 1, 3-state sets it to 2.Ifstate is 2,itsetsitto1.
Interrupt the Spin Callback
If the user clicks the Spin/Stop button when its label is Stop, its callback is
looping through code that updates the display by advancing the rotation of
the surface objects. The
spinstopbutton_Callback contains code that listens
to such events, but it does not u se the
events structure to accomplish this.
Instead, it uses this piece of code to exit the display loop:
if find(strcmp( get( hObject,'String'),handl es.Strings)) == 1
handles.azimuth = az;
guidata(hObject,handles);
break
end
Entering this block of code while spinning the view exits the while loop to
stop the animation. First, however, it saves the current azimuth of rotation
for initializing the next spin. (The
handles structure can store any variable,
not just handles.) If the user clicks the (now) Spin button, the animation
resumes at the place where it halted, using the cached azimuth value.
When the user clicks Quit, the GUI destroys the figure, exiting immediately.
To avoid errors due to quitting while the animation is running, the
while loop
must know whether the axes object still exists:
while ishandle( hand les.axes1)
% plotting code
...
end
You can write the spinstopbut ton_Callback function without a while loop,
which avoid s y ou h aving to test th a t th e figu re s till ex ists. You can, for
example, create a
timer object that handles u pdating the graphics. This
10-22