User`s guide
10 Examples of GUIDE GUIs
startbtn_Callback
startbtn_Callback calls timer start m ethod if the timer is not already
running:
if strcmp(get(h andl es.timer, 'Running' ), 'off')
start(handles.timer);
end
stopbtn_Callback
stopbtn_Callback calls the timer stop method if the timer is currently
running:
if strcmp(get(h andl es.timer, 'Running' ), 'on')
stop(handles.timer);
end
periodsldr_Callback
periodsldr_Callback is called each time you move the slider. It sets timer
period to the slider current value after removing unwanted precision:
% Read the slider value
period = get(handles.periodsldr ,'Value');
% Timers need the precision of periods to be greater than about
% 1 millisecond, so truncat e the value returne d by the slider
period = period - mod(perio d,.01);
% Set slider readout to sho w its value
set(handles.slidervalue,'String',nu m2str(period))
% If timer is on, stop it, reset the peri od, and start it again.
if strcmp(ge t(ha ndles.timer, 'Runni ng') , 'on')
stop(handles.timer);
set(handles.timer,'Period',period)
start(handles.timer)
else % If timer is stopped, reset its period only.
set(handles.timer,'Period',period)
end
The slider callback must stop the tim er to reset its period, because timer
objects do not allow their periods to vary while they are running.
10-110