| MATLAB Function Reference | ![]() |
Syntax
Description
T = timer
constructs a timer object with default attributes.
T = timer('PropertyName1', PropertyValue1, 'PropertyName2',
PropertyValue2,...)
constructs a timer object in which the given Property name/value pairs are set on the object. See Timer Object Properties for a list of all the properties supported by the timer object.
Note that the property name/property value pairs can be in any format supported by the set function, i.e., property/value string pairs, structures, and property/value cell array pairs.
Example
This example constructs a timer object with a timer callback function handle, mycallback, and a 10 second interval.
See Also
delete, disp, get, isvalid, set, start, startat, stop, timerfind, wait
Timer Object Properties
The timer object supports the following properties that control its attributes. The table includes information about the data type of each property and its default value.
To view the value of the properties of a particular timer object, use the get function. To set the value of the properties of a timer object, use the set function.
| Property Name |
Property Description |
Datatypes, Values, and Defaults |
AveragePeriod |
The average time between TimerFcn executions since the timer started.Note: Value is NaN until timer executes two timer callbacks. |
Datatype: doubleDefault: NaNReadonly: Always |
BusyMode |
Action taken when a timer has to execute TimerFcn before the completion of previous execution of TimerFcn. |
Datatype: Enumerated string Values: 'drop'Default: 'drop'Readonly: Only when Running='on' |
ErrorFcn |
Function that the timer executes when an error occurs. This function executes before the StopFcn. See Creating Timer Callback Functions for more information. |
Datatype: Text string, function handle, or cell array. Default: Readonly: Never |
ExecutionMode |
Determines how the timer object schedules timer events. See Timer Execution Modes for more information. |
Datatype: Enumerated string Values: 'singleShot'Readonly: When Running='on' |
InstantPeriod |
The time between the last two executions of TimerFcn. |
Datatype: doubleDefault: NaNReadonly: Always |
Name |
User-supplied name |
Datatype: Text string Default: 'timer-i', where i is a number indicating the ith timer object created this session.Note: If you issue the clear classes command, the timer object resets i to 1.Readonly: Never |
Period |
Specifies the delay, in seconds, between executions of TimerFcn. |
Datatype: doubleValue: Any number <0.001 Default: 1.0 Readonly: When Running='on' |
Running |
Indicates whether the timer is currently executing. |
Datatype: Enumerated string: Values: 'off' 'on'Default: 'off'Readonly: Always |
StartDelay |
Specifies the delay, in seconds, between the start of the timer and the first execution of the function specified in TimerFcn. |
Datatype: doubleValue: Any number <=0Default: 0 Readonly: When Running='on' |
StartFcn |
Function the timer calls when it starts. See Creating Timer Callback Functions for more information. |
Datatype: Text string, function handle, or cell array Default: Readonly: Never |
StopFcn |
Function the timer calls when it stops. The timer stops when:
|
Datatype: Text string, function handle, or cell array. Default: Readonly: Never |
Tag |
User supplied label |
Datatype: Text string Default: ''(empty string) |
TasksToExecute |
Specifies the number of times the timer should execute the function specified in the TimerFcn property. |
Datatype: doubleValue: Any number <0Default: 1 Readonly: Never |
TasksExecuted |
The number of times the timer has executed TimerFcn since the timer was started |
Datatype: doubleValue: Any number <=0 Default: 0 Readonly: Always |
TimerFcn |
Timer callback function. See Creating Timer Callback Functions for more information. |
Datatype: Text string, function handle, or cell array. Default: Readonly: Never |
Type |
Identifies the object type |
Datatype: Text string Value: 'timer'Readonly: Always |
UserData |
User-supplied data |
Datatype: User-defined Default: []Readonly: Never |
| tic, toc | timerfind | ![]() |