23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Starting and Stopping Timers<br />

Starting a Timer at a Specified Time<br />

To start a timer object and specify when you want the timer to fire as a date<br />

and time, rather than as the number of seconds to elapse, use the startat<br />

function.<br />

The startat function starts a timer object running and lets you specify the<br />

date, hour, minute, and second when youwanttothetimertoexecute. You<br />

specify the time as a <strong>MATLAB</strong> serial date number or as a specially formatted<br />

date text string. See the startat function reference page for details.<br />

This example creates a timer object that displays a message after an hour has<br />

elapsed. The startat function starts the timer object running and calculates<br />

the value of the StartDelay property based on the time you specify.<br />

t2=timer('TimerFcn','disp(''It has been an hour now.'')');<br />

startat(t2,now+1/24);<br />

Stopping Timer Objects<br />

Once started, the timer object stops running if one of the following conditions<br />

apply:<br />

• The timer function callback (TimerFcn) has been executed the number of<br />

times specified in the TasksToExecute property.<br />

• An error occurred while executing a timer function callback (TimerFcn).<br />

You can also stop a timer object by using the stop function, specifying the<br />

timer object as the only argument. The following example illustrates stopping<br />

a timer object:<br />

1 Create a timer object.<br />

t = timer('TimerFcn','disp(''Hello World!'')', ...<br />

'StartDelay', 100);<br />

2 Start it running.<br />

start(t)<br />

10-11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!