23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

10 Scheduling Program Execution with Timers<br />

2 Specify the value of the StartFcn callback. Note that the example specifies<br />

the value in a cell array because the callback function needs to access<br />

arguments passed to it.<br />

t.StartFcn = {'my_callback_fcn', 'My start message'};<br />

3 Specify the value of the StopFcn callback. The example specifies the<br />

callback function by its handle, rather than as a text string. Again, the<br />

value is specified in a cell array because the callback function needs to<br />

access the arguments passed to it.<br />

t.StopFcn = { @my_callback_fcn, 'My stop message'};<br />

4 Specify the value of the TimerFcn callback. The example specifies the<br />

<strong>MATLAB</strong> commands in a text string.<br />

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

5 Start the timer object.<br />

start(t)<br />

The example outputs the following.<br />

StartFcn event occurred at 10-Mar-2004 17:16:59<br />

Start message<br />

Hello World!<br />

Hello World!<br />

StopFcn event occurred at 10-Mar-2004 17:16:59<br />

Stop message<br />

6 Delete the timer object after you are finished with it.<br />

delete(t)<br />

10-18

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

Saved successfully!

Ooh no, something went wrong!