stop

Class:timer

Stop timer object

Syntax

Description

example

stop(t)stops the timer object,t. Iftis an array of timer objects, thestopmethod stops each timer.

Thestopmethod sets theRunningproperty of the timer object to'off'and executes theStopFcncallback .

Input Arguments

t

Object of classtimer.

Examples

expand all

Create a timer object that generates 100 random numbers and executes one million times. Define aStopFcncallback that displays the message 'Timer has stopped.' Start the timer and verify the timer is running

t = timer('TimerFcn','rand(100,1);',...'ExecutionMode','fixedSpacing','TasksToExecute',1e6,...'StopFcn','disp(''Timer has stopped.'')'); start(t) t.Running
ans = '在'

Manually stop the timer and verify it is no longer running. Delete the timer.

停止(t) t.Running
ans = 'off'
delete(t)

Tips

  • Use thestopmethod to stop a timer manually. The timer automatically stops when theTimerFcncallback executes the number of times specified by theExecutionModeandTasksToExecuteproperties or when an error occurs while executing aTimerFcncallback.

Introduced before R2006a