Programming and Data Types    

Using MATLAB Timers

MATLAB includes a timer object that you can use to schedule the execution of MATLAB commands. To use a timer, perform these steps:

  1. Create a timer object by calling the timer function. See Creating and Deleting Timer Objects for more information.
  2. Set the values of timer object properties to specify which MATLAB commands you want executed and when you want them executed. (You can also set timer object properties when you create them, in Step 1.) See Timer Object Properties for information about all the properties supported by the timer object.
  3. Start the timer by calling the start or startat function. See Starting and Stopping Timers for more information.

For example, this code sets up a timer that executes a MATLAB command string after 10 seconds elapse. The example creates a timer object, specifying the values of two timer object properties, TimerFcn and StartDelay. TimerFcn specifies the timer callback function. This is the MATLAB command string or M-file that you want to execute. StartDelay specifies how much time elapses before the timer executes the callback function.

After creating the timer object, the example uses the start function to start the timer. (The additional commands in this example are included to illustrate the timer but are not required for timer operation.)

When you execute this code, it produces this output:


  Shell Escape Functions Creating and Deleting Timer Objects