ex_guide_timergui_OpeningFcn
The ex_guide_timergui_OpeningFcn function executes when the app opens and
starts running. This command creates the timer object and stores it in the handles
structure.
handles.timer = timer(...
'ExecutionMode', 'fixedRate', ... % Run timer repeatedly.
'Period', 1, ... % Initial period is 1 sec.
'TimerFcn', {@update_display,hObject}); % Specify callback function.
The callback function for the timer is update_display, which is defined as a local
function.
update_display
The update_display function executes when the specified timer period elapses. The
function gets the values in the ZData property of the Surface object and adds random
noise to it. Then it updates the plot.
handles = guidata(hfigure);
Z = get(handles.surf,'ZData');
Z = Z + 0.1*randn(size(Z));
set(handles.surf,'ZData',Z);
periodsldr_Callback
The periodsldr_Callback function executes when the user moves the slider. It
calculates the timer period by getting the slider value and truncating it. Then it updates
the label below the slider and updates the period of the timer object.
% Read the slider value
period = get(handles.periodsldr,'Value');
% Truncate the value returned by the slider.
period = period - mod(period,.01);
% Set slider readout to show its value.
set(handles.slidervalue,'String',num2str(period))
% If timer is on, stop it, reset the period, and start it again.
if strcmp(get(handles.timer, 'Running'), 'on')
stop(handles.timer);
set(handles.timer,'Period',period)
start(handles.timer)
else % If timer is stopped, reset its period.
set(handles.timer,'Period',period)
end
Automatically Refresh Plot in a GUIDE App