how to run a callback function

4 views (last 30 days)
grapevine
grapevine on 11 May 2012
Hello everyone,
I can figure out the way to call a callback function from a Matlab script. I saw the syntax: function myfile(obj, event) http://www.mathworks.nl/help/techdoc/matlab_prog/f9-39541.html
but I still feel a little bit lost about the meanings of the argument obj and _event_ can you please give me some example? For example if I want to run the OpenFcn function, which is one of the callbacks listed in the block property, how can I do that?
thanks for reading

Answers (1)

Jan
Jan on 11 May 2012
As explained in the documentation (read the Getting Started chapters and search for "callback"), obj is a handle of the calling object, e.g. the figure or a uicontrol. The variable event is a struct, which explains the event, which has triggered the callback. The contents of the variable depends on the type of the callback, e.g. an activated UICONTROL replies another event description as a CellSelectedCallback of a uitable.
You can set a breakpoint in the callback and inspect the contents of the event variable in the command window or the workspace browser to learn more. Because the event struct has been the empty matrix in old Matlab versions, you can get nearly all possible actions and informations just by using the object handle and its properties.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!