Programming and Data Types    

Creating Timer Callback Functions

Four of the timer object properties specify callback functions that the timer object executes:

As the value of these properties, you can specify:

When you set the value of these properties, you can specify arguments for the callback function using any of the following syntaxes.

Callback Function Syntax
Example
Function myfile
set(h, 'StartFcn', 'myfile')
Function myfile(obj, event)
set(h, 'StartFcn', @myfile)
Function myfile(obj, event, arg1, arg2)
set(h, 'StartFcn', {'myfile', 5, 6})
Function myfile(obj, event, arg1, arg2)
set(h, 'StartFcn', {@myfile, 5, 6})

The following diagram illustrates when the timer object executes the StartFcn, StopFcn, and TimerFcn. The ErrorFcn can occur at any time.

In this figure, the timer stops after two executions of the timer callback function (TimerFcn):


  Timer Object Execution Modes Character Arrays (Strings)