Please explain inconsistent use of parameters within UI handle function calls.
Ältere Kommentare anzeigen
In the code below, there are two UI calls which require function handles. 'fig' and 'myQuititem' are objects. In the fig.CloseRequestFcn call two parameter are passed along with the function handle just after the @ and the function definition below does not require a parameter list. In the myQuitItem.MenuSelectedFcn call, no parameters are passed after the @, but the function definition absolutely requires two parameters 'src' and 'event'. The is very confusing. Why the two different ways of passing parameters? What is different between these two methods? These are both nested functions and so the object 'fig' is available to both functions, but what if they were not nested? How would you pass the object fig to the functions?
8 Kommentare
Christopher McKenzie
am 27 Mär. 2020
Christopher McKenzie
am 27 Mär. 2020
Bearbeitet: Christopher McKenzie
am 28 Mär. 2020
Tommy
am 28 Mär. 2020
If you are interested, another way to pass extra parameters without using an anonymous function is
myQuitItem.MenuSelectedFcn = {@quitThisWindow,fig};
Christopher McKenzie
am 28 Mär. 2020
Bearbeitet: Christopher McKenzie
am 28 Mär. 2020
Christopher McKenzie
am 28 Mär. 2020
Tommy
am 28 Mär. 2020
You're right about the function definition. And I think you've also got the right idea with your second comment. CloseRequestFcn is a property of a figure object which you are setting equal to some method in the methods block.
Christopher McKenzie
am 28 Mär. 2020
Steven Lord
am 28 Mär. 2020
While
methods uifigure
won't work because as you said uifigure is a function that returns an object not a class itself, methods can accept an object as input and will return the methods of the class of that object.
methods(uifigure)
The command form passes the text 'uifigure' into methods while the function form passes the object returned by calling uifigure into methods.
Antworten (0)
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
