Main Content

start

Syntax

Description

example

start(t) starts the timer t. If t is an array of timers, start starts all the timers.

The start function sets the Running property of the timer to 'on', executes the StartFcn callback, and initiates TimerFcn callback.

Examples

collapse all

Use start to start a timer.

Create and start a timer that displays the message "timer started." as the StartFcn callback and generates a random number as the TimerFcn callback. Delete the timer.

t = timer('StartFcn',@(~,~)disp('timer started.'),...
          'TimerFcn',@(~,~)disp(rand(1)));
start(t)
delete(t)
timer started.
    0.9706

Your output from rand will vary.

Use start to begin multiple timers.

Create and start three timers that display message for the StartFcn callbacks. Compute the sine, cosine, and tangent of pi/4 as the TimerFcn callbacks. Delete the timers.

t1 = timer('StartFcn',@(~,~)disp('t1 started.'),...
           'TimerFcn',@(~,~)sin(pi/4)); 
t2 = timer('StartFcn',@(~,~)disp('t2 started.'),...
           'TimerFcn',@(~,~)cos(pi/4)); 
t3 = timer('StartFcn',@(~,~)disp('t3 started.'),...
           'TimerFcn',@(~,~)tan(pi/4)); 
start([t1 t2 t3]);
delete([t1 t2 t3]);
t1 started.
t2 started.
t3 started.

Input Arguments

collapse all

Timer to start, specified as a timer or array of timers.

See Also

| | |

Introduced before R2006a