Main Content

stop

Syntax

Description

example

stop(t) stops the timer object t. If t is an array of timer objects, stop stops each timer.

The stop function sets the Running property of the timer object to 'off' and executes the StopFcn callback.

Examples

collapse all

Create a timer object that generates 100 random numbers and executes 1,000,000 times. Define a StopFcn callback 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 = 
'on'

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

stop(t)
t.Running
ans = 
'off'

Delete the timer.

delete(t)

Use the timerfind function to stop multiple timers at the same time even when the timer variables have been removed from the workspace.

Create two timer objects that generates 100 random numbers and executes 1,000,000 times. Define a StopFcn callback that displays the message 'Timer has stopped.' Start the timers and verify that the timer is running.

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 the timer variables from the workspace

clear

Use the timerfind function to manually stop the timers and verify that they are no longer running.

stop(timerfind)
t1.Running
ans = 
'off'
t2.Running
ans = 
'off'

Delete the timers.

delete(timerfind)

Input Arguments

collapse all

Timer to stop, specified as a timer object or array of timer objects.

Example: stop(t)

Tips

  • Use the stop method to stop a timer manually. The timer automatically stops when the TimerFcn callback executes the number of times specified by the ExecutionMode and TasksToExecute properties or when an error occurs while executing a TimerFcn callback.

Version History

Introduced before R2006a

See Also

| | |