Schedule Command Execution Using Timer
In this section...
“Overview” on page 27-2
“Example: Displaying a Message” on page 27-3
Overview
The MATLAB software includes a timer object that you can use to schedule the execution
of MATLAB commands. This section describes how you can create timer objects, start a
timer running, and specify the processing that you want performed when a timer fires. A
timer is said to fire when the amount of time specified by the timer object elapses and the
timer object executes the commands you specify.
To use a timer, perform these steps:
1 Create a timer object.
You use the timer function to create a timer object.
2 Specify which MATLAB commands you want executed when the timer fires and
control other aspects of timer object behavior.
You use timer object properties to specify this information. To learn about all the
properties supported by the timer object, see timer and set. You can also set timer
object properties when you create them, in step 1.
3 Start the timer object.
After you create the timer object, you must start it, using either the start or
startat function.
4 Delete the timer object when you are done with it.
After you are finished using a timer object, you should delete it from memory. See
delete for more information.
NoteThe specified execution time and the actual execution of a timer can vary because
timer objects work in the MATLAB single-threaded execution environment. The length of
this time lag is dependent on what other processing MATLAB is performing. To force the
execution of the callback functions in the event queue, include a call to the drawnow
function in your code. The drawnow function flushes the event queue.
27 Program Scheduling