timer
Schedule execution of MATLAB commands
Description
Use a timer
to schedule one or multiple executions of tasks
comprised of MATLAB® callback functions. If a timer is scheduled to execute multiple times, you can
specify the time between executions and how to handle queuing conflicts by adjusting the
properties of the timer.
The timer
object uses callback functions to execute commands. Callback
functions execute code during some event, elapsed time in the case of
timer
. For the timer
object, you can specify the
callback function as a function handle or as a character vector. If the callback function is a
character vector, MATLAB evaluates it as executable code. The timer object supports callback functions
when a timer starts (StartFcn
), executes (TimerFcn
),
stops (StopFcn
), or encounters an error (ErrorFcn
). For
more information related to callback functions, see Timer Callback Functions.
Creation
Description
creates an empty
t
= timertimer
object to schedule execution of MATLAB commands. Before starting the timer, you must set the
TimerFcn
property for the timer object.
A timer t
has properties that control its behavior. Access a
property by using p = t.Property
and modify one using
t.Property = p
. To save and restore all properties of
t
, you can use A = get(t)
and
set(t,A)
, respectively.
Specifies additional options that use one or more t
= timer(Name,Value
)Name-Value
arguments.
Properties
Object Functions
delete | Delete files or objects |
get | Query graphics object properties |
isvalid | Determine valid handles |
set | Set graphics object properties |
start | Start timer |
startat | Schedule timer to fire at specified time |
stop | Stop timer |
timerfind | Find timer objects |
timerfindall | Find all timer objects |
wait | Block command prompt until timer stops running |
Examples
Limitations
The
timer
object is subject to the limitations of your hardware, operating system, and software. Avoid usingtimer
objects for real-time applications. If MATLAB is busy processing another task, the timer callback might not execute.Using
wait
inside timer callback functions is discouraged.
Tips
To force the execution of the callback functions in the event queue, include a call to the
drawnow
function. Thedrawnow
function flushes the event queue.
Version History
Introduced before R2006a