how to run a callback function

6 次查看(过去 30 天)
grapevine
grapevine 2012-5-11
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

回答(1 个)

Jan
Jan 2012-5-11
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.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by