stop

Class: timer

Stop timer object

Syntax

Description

example

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

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

Input Arguments

t

Object of class timer.

Examples

expand all

Create a timer object that generates 100 random numbers and executes one million 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 it is no longer running. Delete the timer.

stop(t)
t.Running
ans = 
'off'
delete(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.

See Also

| | |

Introduced before R2006a