Example: Displaying a Message
The following example sets up a timer object that executes a MATLAB command
character vector after 10 seconds elapse. The example creates a timer object, specifying
the values of two timer object properties, TimerFcn and StartDelay. TimerFcn
specifies the timer callback function. This is the MATLAB command or program file that
you want to execute when the timer fires. In the example, the timer callback function sets
the value of the MATLAB workspace variable stat and executes the MATLAB disp
command. The StartDelay property specifies how much time elapses before the timer
fires.
After creating the timer object, the example uses the start function to start the timer
object. (The additional commands in this example are included to illustrate the timer but
are not required for timer operation.)
t = timer('TimerFcn', 'stat=false; disp(''Timer!'')',...
'StartDelay',10);
start(t)
stat=true;
while(stat==true)
disp('.')
pause(1)
end
When you execute this code, it produces this output:
.........
Timer!
delete(t) % Always delete timer objects after using them.
See Also
timer
See Also