[转]Matlab Timer的属性设置

本文详细介绍了 Matlab 中定时器对象的使用方法及其属性设置,包括不同执行模式的特点及如何配置定时器的各项参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Simple sample:

>> t=timer('TimerFcn','disp("Hello!")','Period',3,'ExecutionMode','fixedSpacing','TasksToExecute',5);
>> start(t)

要说明的是定时的时间会在某个时刻到达,但此时不一定会立刻执行TimerFcn,但它(TimerFcn的执行)会被立即加入到Matlab的执行语句队列中去排队,等到队列中前面的语句都执行完了,才被执行。这里语句的执行也会花一段时间。执行模式就针对这些3个时刻而提出:加入执行语句队列的时刻,开始执行的时刻,执行完毕的时刻

ExecutionMode   执行的模式:
          'singleShot'    :只能执行一次,其他模式都可以执行多次
          'fixedSpacing' :上一次执行完毕的时刻到下一次被加入队列的时刻之间的间隔是指定的固定时间长度
          'fixedDelay'    :上一次开始执行的时刻到下一次被加入队列的时刻之间的间隔是指定的固定时间长度
          'fixedRate'     :两次被加入到执行语句队列的时刻之间的间隔是指定的固定时间长度

Period       指定的时间间隔: 秒为单位,通常最小值为毫秒, 默认为1(秒)


StartDelay 启动时延 : 从调用start(t1),开始到第一次把TimerFcn的执行加入到Matlab的执行语句队列中去的时延, 默认值为0(秒)          

TasksToExecute TimerFcn将被执行的次数,默认为1(次)

TimerFcn        在制定事可将被执行的函数



其它参数, 详见help文档。 不对之处,欢迎批评指正!

Property NameProperty DescriptionDatatypes, 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: double
Default:     NaN
Readonly: Always
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.
  • 'queue'--Execute function at next opportunity.
Datatype: Enumerated string
Values: 'drop'
         'queue'
          'error'

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'
          'fixedSpacing'
          'fixedDelay'
          'fixedRate'
Default:   'singleShot'

Readonly: When Running='on'
InstantPeriod
The time between the last two executions of TimerFcn.Datatype: double
Default:    NaN
Readonly: Always
Name
User-supplied nameDatatype: 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: double
Value:        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: double
Value:        Any number <=0
Default:     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:
  • You call the timer stop function
  • When the timer finishes executing TimerFcn, i.e., the value of TasksExecuted reaches the limit set by the TasksToExecute.
  • An error occurs (The ErrorFcn is called first, followed by the StopFcn.)
See Creating Timer Callback Functions for more information.
Datatype: Text string, function
                   handle, or cell array.
Default:     
Readonly: Never
Tag
User supplied labelDatatype: Text string
Default: ''(empty string)
TasksToExecute
Specifies the number of times the timer should execute the function specified in the TimerFcn property.Datatype: double
Value:        Any number <0
Default:    1
Readonly: Never
TasksExecuted
The number of times the timer has executed TimerFcn since the timer was startedDatatype: double
Value:        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 typeDatatype: Text string
Value:      'timer'
Readonly: Always
UserData
User-supplied dataDatatype: User-defined
Default:    []
Readonly: Never
转自: http://hi.baidu.com/nannanblog/blog/item/214b73d783b108d9a044df6e.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值