23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creating and Executing Callback Functions<br />

msg = [event_type txt1 event_time];<br />

disp(msg)<br />

disp(txt2)<br />

Specifying the Value of Callback Function Properties<br />

You associate a callback function with a specific event by setting the value of<br />

the appropriate callback property. You can specify the callback function as<br />

a text string, cell array, or function handle. To access the object and event<br />

arguments, you must specify the function as a cell array or as a function<br />

handle. If your callback function accepts additional arguments, you must<br />

use a cell array.<br />

The following table shows the syntax for several sample callback functions<br />

and describes how you call them.<br />

Callback Function Syntax<br />

function myfile<br />

function myfile(obj, event)<br />

function myfile(obj, event,<br />

arg1, arg2)<br />

function myfile(obj, event,<br />

arg1, arg2)<br />

How to Specify as a Property<br />

Value<br />

set(h, 'StartFcn', 'myfile')<br />

set(h, 'StartFcn', @myfile)<br />

set(h, 'StartFcn', {'myfile',<br />

5, 6})<br />

set(h, 'StartFcn', {@myfile,<br />

5, 6})<br />

This example illustrates several ways you can specify the value of timer object<br />

callback function properties, some with arguments and some without. To see<br />

the code of the callback function, my_callback_fcn, see“Example:Writinga<br />

Callback Function” on page 10-16.<br />

1 Create a timer object.<br />

t = timer('StartDelay', 4,'Period', 4,'TasksToExecute', 2,...<br />

'ExecutionMode','fixedRate');<br />

10-17

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

Saved successfully!

Ooh no, something went wrong!