stop
停止计时器
语法
说明
示例
停止正在进行的计时器
创建一个计时器对象,以生成 100 个随机数并执行一百万次。定义 StopFcn
回调,以显示消息“Timer has stopped.”。启动计时器并确认计时器正在运行
t = timer('TimerFcn','rand(100,1);',... 'ExecutionMode','fixedSpacing','TasksToExecute',1e6,... 'StopFcn','disp(''Timer has stopped.'')'); start(t) t.Running
ans = 'on'
手动停止计时器并确认它不再运行。
stop(t) t.Running
ans = 'off'
删除该计时器。
delete(t)
停止所有计时器
使用 timerfind
函数可以同时停止多个计时器,即使计时器变量已从工作区中删除也是如此。
创建两个计时器对象,它们生成 100 个随机数并执行一百万次。定义 StopFcn
回调,以显示消息“Timer has stopped.”。启动计时器并验证计时器是否正在运行。
t1 = timer('TimerFcn','rand(100,1);',... 'ExecutionMode','fixedSpacing','TasksToExecute',1e6,... 'StopFcn','disp(''Timer1 has stopped.'')'); t2 = timer('TimerFcn','rand(100,1);',... 'ExecutionMode','fixedSpacing','TasksToExecute',1e6,... 'StopFcn','disp(''Timer2 has stopped.'')'); start([t1 t2])
从工作区中清除计时器变量
clear
使用 timerfind
函数手动停止计时器,并确认它们不再运行。
stop(timerfind) t1.Running
ans = 'off'
t2.Running
ans = 'off'
删除这些计时器。
delete(timerfind)
输入参数
t
— 计时器对象
计时器对象 | 计时器对象数组
要停止的计时器,指定为计时器对象或计时器对象数组。
示例: stop(t)
提示
使用
stop
方法可手动停止计时器。如果TimerFcn
回调执行ExecutionMode
和TasksToExecute
属性指定的次数,或者在执行TimerFcn
回调时出现错误,计时器将会自动停止。
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)