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.

10 Scheduling Program Execution with Timers<br />

Starting and Stopping Timers<br />

After you create a timer object, you can start the timer by calling either the<br />

start or startat function. This section describes<br />

• “Starting a Timer” on page 10-10<br />

• “Starting a Timer at a Specified Time” on page 10-11<br />

• “Stopping Timer Objects” on page 10-11<br />

• “Blocking the <strong>MATLAB</strong> Command Line” on page 10-12<br />

Note Because the timer works within the <strong>MATLAB</strong> single-threaded<br />

environment, it cannot guarantee execution times or execution rates.<br />

Starting a Timer<br />

To start a timer object, call the start function, specifying the timer object<br />

as the only argument. The start function starts a timer object running;<br />

the amount of time the timer runs is specified in seconds in the StartDelay<br />

property.<br />

This example creates a timer object that displays a greeting after 5 seconds<br />

elapse.<br />

1 Create a timer object, specifying values for timer object properties.<br />

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

2 Start the timer object.<br />

start(t)<br />

3 Delete the timer object after you are finished using it.<br />

delete(t);<br />

10-10

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

Saved successfully!

Ooh no, something went wrong!