Working with Timer Object Properties

To get information about timer object properties, see the timer function reference page.

Retrieving the Value of Timer Object Properties

The timer object supports many properties that provide information about the current state of the timer object and control aspects of its functioning. To retrieve the value of a timer object property, you can use the get function or use subscripts (dot notation) to access the field.

The following example uses the set function to retrieve the value of the ExecutionMode property:

t = timer;

tmode = get(t,'ExecutionMode')

tmode =

singleShot

The following example uses dot notation to retrieve the value of the ExecutionMode property:

tmode = t.ExecutionMode

tmode =

singleShot

To view a list of all the properties of a timer object, use the get function, specifying the timer object as the only argument:

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.

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...'')'
  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
  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS