timer class
Create object to schedule execution ofMATLABcommands
Description
Use atimer
object to schedule the execution of MATLAB®commands one or multiple times. If you schedule the timer to execute multiple times, you can define the time between executions and how to handle queuing conflicts.
Thetimer
object uses callback functions to execute commands. Callback functions execute code during some event. For thetimer
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
).
Note
Thetimer
object is subject to the limitations of your hardware, operating system, and software. Avoid using timer objects for real-time applications.
Construction
creates an emptyt
=计时器timer
object to schedule execution of MATLAB commands. An error occurs if the timer starts andTimerFcn
is not defined.
creates at
=计时器(Name,Value
)timer
object with additional options that you specify using one or moreName,Value
pair arguments.
Input Arguments
Name-Value Pair Arguments
Specify optional comma-separated pairs ofName,Value
arguments.Name
is the argument name andValue
is the corresponding value.Name
must appear inside single quotes (' '
). You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN
.
The argument name,Name
, corresponds to atimer
property name. In the constructor, the property values are specified usingName,Value
pair arguments.
|
Character vector that indicates action taken when a timer has to execute
SeeHandling Timer Queuing Conflictsfor more information. Default: |
||||||||||||||||
|
Character vector, function handle, or cell array defining the function that the timer executes when an error occurs. If there is an error, this function executes, and then calls
For more information, seeTimer Callback Functions. |
||||||||||||||||
|
特征向量定义w the
Default: |
||||||||||||||||
|
Character vector representing the Default: |
||||||||||||||||
|
Character vector with possible values of Default: |
||||||||||||||||
|
Number greater than 0.001 that specifies the delay, in seconds, between executions of Default:1.0 |
||||||||||||||||
|
Number greater than or equal to 0 that specifies the delay, in seconds, between the start of the timer and the first execution of the function specified in Default:0 |
||||||||||||||||
|
Character vector, function handle, or cell array defining the function that executes when the timer starts.
For more information, seeTimer Callback Functions. |
||||||||||||||||
|
Character vector, function handle, or cell array defining the function that executes when the timer stops.
For more information, seeTimer Callback Functions. The timer stops when
You can use |
||||||||||||||||
|
Character vector that represents a label for the object. |
||||||||||||||||
|
Number greater than 0, indicating the number of times the timer object is to execute the Default: |
||||||||||||||||
|
Character vector, function handle, or cell array defining the timer callback function. You must define this property before you can start the timer.
For more information, seeTimer Callback Functions. |
||||||||||||||||
|
Generic field for data that you want to add to the object. |
Properties
|
Average time in seconds between |
|
The time in seconds between the last two executions of |
|
Character vector defined as |
|
The number of times the timer called |
|
Character vector that identifies the object type. |
Methods
delete | Remove timer object from memory |
get | Query property values for timer object |
isvalid | Determine timer object validity |
set | Set property values for timer object |
start | Start timer object |
startat | Schedule timer to fire at specified time |
stop | Stop timer object |
timerfind | Find timer object |
timerfindall | Find timer object, regardless of visibility |
wait | Block command prompt until timer stops running |
Copy Semantics
Handle. To learn how handle classes affect copy operations, seeCopying Objects.
Examples
Tips
To force the execution of the callback functions in the event queue, include a call to the
drawnow
function in your code. Thedrawnow
function flushes the event queue.