msg = [event_type txt1 event_time];
disp(msg)
disp(txt2)
Specifying the Value of Callback Function Properties
You associate a callback function with a specific event by setting the value of the
appropriate callback property. You can specify the callback function as a cell array or
function handle. If your callback function accepts additional arguments, you must use a
cell array.
The following table shows the syntax for several sample callback functions and describes
how you call them.
Callback Function Syntax How to Specify as a Property Value for
Object t
function myfile(obj, event) t.StartFcn = @myfile
function myfile t.StartFcn = @(~,~)myfile
function myfile(obj, event, arg1,
arg2)
t.StartFcn = {@myfile, 5, 6}
This example illustrates several ways you can specify the value of timer object callback
function properties, some with arguments and some without. To see the code of the
callback function, my_callback_fcn, see “Example: Writing a Callback Function” on
page 27-7:
1 Create a timer object.
t = timer('StartDelay', 4, 'Period', 4, 'TasksToExecute', 2, ...
'ExecutionMode', 'fixedRate');
2 Specify the value of the StartFcn callback. Note that the example specifies the
value in a cell array because the callback function needs to access arguments passed
to it:
t.StartFcn = {@my_callback_fcn, 'My start message'};
3 Specify the value of the StopFcn callback. Again, the value is specified in a cell array
because the callback function needs to access the arguments passed to it:
t.StopFcn = { @my_callback_fcn, 'My stop message'};
4 Specify the value of the TimerFcn callback. The example specifies the MATLAB
commands in a character vector:
27 Program Scheduling