Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

timer - Construct timer object

Syntax

T = timer
T = timer('PropertyName1', PropertyValue1, 'PropertyName2', PropertyValue2,...)

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.

Examples

This example constructs a timer object with a timer callback function handle, mycallback, and a 10 second interval.

t = timer('TimerFcn',@mycallback, 'Period', 10.0);

See Also

delete(timer), disp(timer), get(timer), isvalid(timer), set(timer), start, startat, stop, timerfind, timerfindall, 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(timer) function. To set the value of the properties of a timer object, use the set(timer) function.

Property Name

Property Description

Data Types, Values, Defaults, Access

AveragePeriod

Average time between TimerFcn executions since the timer started.

Note: Value is NaN until timer executes two timer callbacks.

Data typedouble
DefaultNaN
Read onlyAlways
BusyMode

Action taken when a timer has to execute TimerFcn before the completion of previous execution of TimerFcn.


   'drop' — Do not execute the function.

   'error' — Generate an error. Requires ErrorFcn to be set.

   'queue' — Execute function at next opportunity.

Data typeEnumerated string
Values'drop'
'error'
'queue'
Default'drop'
Read onlyWhile Running = 'on'
ErrorFcn

Function that the timer executes when an error occurs. This function executes before the StopFcn. See Creating Callback Functions for more information.

Data typeText string, function handle, or cell array
DefaultNone
Read onlyNever
ExecutionMode

Determines how the timer object schedules timer events. See Timer Object Execution Modes for more information.

Data typeEnumerated string
Values'singleShot'
'fixedDelay'
'fixedRate'
'fixedSpacing'
Default'singleShot'
Read onlyWhile Running = 'on'
InstantPeriod

The time between the last two executions of TimerFcn.

Data typedouble
DefaultNaN
Read onlyAlways
Name

User-supplied name.

Data typeText string
Default'timer-i', where i is a number indicating the ith timer object created this session. To reset i to 1, execute the clear classes command.
Read onlyNever
ObjectVisibility

Provides a way for application developers to prevent end-user access to the timer objects created by their application. The timerfind function does not return an object whose ObjectVisibility property is set to 'off'. Objects that are not visible are still valid. If you have access to the object (for example, from within the M-file that created it), you can set its properties.

Data typeEnumerated string
Values'off'
'on'
Default'on'
Read onlyNever
Period

Specifies the delay, in seconds, between executions of TimerFcn.

Data typedouble
ValueAny number >= 0.001
Default1.0
Read onlyWhile Running = 'on'
Running

Indicates whether the timer is currently executing.

Data typeEnumerated string
Values'off'
'on'
Default'off'
Read onlyAlways
StartDelay

Specifies the delay, in seconds, between the start of the timer and the first execution of the function specified in TimerFcn.

Data typedouble
ValuesAny number >= 0
Default0
Read onlyWhile Running ='on'
StartFcn

Function the timer calls when it starts. See Creating Callback Functions for more information.

Data typeText string, function handle, or cell array
DefaultNone
Read onlyNever
StopFcn

Function the timer calls when it stops. The timer stops when

  • You call the timer stop function

  • The timer finishes executing TimerFcn, i.e., the value of TasksExecuted reaches the limit set by TasksToExecute.

  • An error occurs
    (The ErrorFcn is called first, followed by the StopFcn.)

See Creating Callback Functions for more information.

Date typeText string, function handle, or cell array
DefaultNone
Read onlyNever
Tag

User supplied label.

Data typeText string
DefaultEmpty string ('')
Read onlyNever
TasksToExecute

Specifies the number of times the timer should execute the function specified in the TimerFcn property.

Data typedouble
ValuesAny number > 0
DefaultInf
Read onlyNever
TasksExecuted

The number of times the timer has called TimerFcn since the timer was started.

Data typedouble
ValuesAny number >= 0
Default0
Read onlyAlways
TimerFcn

Timer callback function. See Creating Callback Functions for more information.

Data typeText string, function handle, or cell array
DefaultNone
Read onlyNever
Type

Identifies the object type.

Data typeText string
Values'timer'
Read onlyAlways
UserData

User-supplied data.

Data typeUser-defined
Default[]
Read onlyNever

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS