MATLAB Programming

MATLAB Programming MATLAB Programming

cda.psych.uiuc.edu
from cda.psych.uiuc.edu More from this publisher
23.06.2015 Views

10 Scheduling Program Execution with Timers get(t) AveragePeriod: NaN BusyMode: 'drop' ErrorFcn: '' ExecutionMode: 'singleShot' InstantPeriod: NaN Name: 'timer-4' ObjectVisibility: 'on' Period: 1 Running: 'off' StartDelay: 0 StartFcn: '' StopFcn: '' Tag: '' TasksExecuted: 0 TasksToExecute: Inf TimerFcn: '' Type: 'timer' UserData: [] Setting the Value of Timer Object Properties To set the value of a timer object property, use the set function or subscripted assignment (dot notation). You can also set timer object properties when you create the timer object. For more information, see “Creating Timer Objects” on page 10-5. The following example uses both methods to assign values to timer object properties. The example creates a timer that, once started, displays a message every second until you stop it with the stop command. 1 Create a timer object. t = timer; 2 Assign values to timer object properties using the set function. set(t,'ExecutionMode','fixedRate','BusyMode','drop','Period',1); 3 Assign a value to the timer object TimerFcn property using dot notation. t.TimerFcn = 'disp(''Processing...'')' 10-8

Working with Timer Object Properties 4 Start the timer object. It displays a message at 1-second intervals. start(t) 5 Stop the timer object. stop(t) 6 Delete timer objects after you are done using them. delete(t) Viewing a List of All Settable Properties To view a list of all timer object properties that can have values assigned to them (in contrast to the read-only properties), use the set function, specifying the timer object as the only argument. The display includes the values you can use to set the property if, like the BusyMode property, the property accepts an enumerated list of values. t = timer; set(t) BusyMode: [ {drop} | queue | error ] ErrorFcn: string -or- function handle -or- cell array ExecutionMode: [{singleShot} | fixedSpacing | fixedDelay | fixedRate] Name ObjectVisibility: [ {on} | off ] Period StartDelay StartFcn: string -or- function handle -or- cell array StopFcn: string -or- function handle -or- cell array Tag TasksToExecute TimerFcn: string -or- function handle -or- cell array UserData 10-9

10 Scheduling Program Execution with Timers<br />

get(t)<br />

AveragePeriod: NaN<br />

BusyMode: 'drop'<br />

ErrorFcn: ''<br />

ExecutionMode: 'singleShot'<br />

InstantPeriod: NaN<br />

Name: 'timer-4'<br />

ObjectVisibility: 'on'<br />

Period: 1<br />

Running: 'off'<br />

StartDelay: 0<br />

StartFcn: ''<br />

StopFcn: ''<br />

Tag: ''<br />

TasksExecuted: 0<br />

TasksToExecute: Inf<br />

TimerFcn: ''<br />

Type: 'timer'<br />

UserData: []<br />

Setting the Value of Timer Object Properties<br />

To set the value of a timer object property, use the set function or subscripted<br />

assignment (dot notation). You can also set timer object properties when you<br />

create the timer object. For more information, see “Creating Timer Objects”<br />

on page 10-5.<br />

The following example uses both methods to assign values to timer object<br />

properties. The example creates a timer that, once started, displays a message<br />

every second until you stop it with the stop command.<br />

1 Create a timer object.<br />

t = timer;<br />

2 Assign values to timer object properties using the set function.<br />

set(t,'ExecutionMode','fixedRate','BusyMode','drop','Period',1);<br />

3 Assign a value to the timer object TimerFcn property using dot notation.<br />

t.TimerFcn = 'disp(''Processing...'')'<br />

10-8

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

Saved successfully!

Ooh no, something went wrong!