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.

Creating Timer Objects<br />

Creating Timer Objects<br />

Touseatimerin<strong>MATLAB</strong>,youmustcreateatimerobject.Thetimerobject<br />

represents the timer in <strong>MATLAB</strong>, supporting various properties and functions<br />

that control its behavior.<br />

To create a timer object, use the timer function. This creates a valid timer<br />

object with default values for most properties. The following shows an<br />

example of the default timer object and its summary display:<br />

t = timer<br />

Timer Object: timer-1<br />

Timer Settings<br />

ExecutionMode: singleShot<br />

Period: 1<br />

BusyMode: drop<br />

Running: off<br />

Callbacks<br />

TimerFcn: ''<br />

ErrorFcn: ''<br />

StartFcn: ''<br />

StopFcn: ''<br />

<strong>MATLAB</strong> names the timer object timer-1. (See “Timer Object Naming” on<br />

page 10-6 for more information.)<br />

To specify the value of timer object properties after you create it, you can use<br />

the set function. This example sets the value of the TimerFcn property and<br />

the StartDelay property. For more information about timer object properties,<br />

see “Working with Timer Object Properties” on page 10-7.<br />

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

You can also set timer object properties when you create the timer object by<br />

specifying property name and value pairs as arguments to the timer function.<br />

The following example sets the same properties at object creation time:<br />

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

10-5

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

Saved successfully!

Ooh no, something went wrong!