What is the syntax for using multiple inputs for a callback function within a gui set command?
5 views (last 30 days)
Show older comments
phillip stallworth
on 29 Apr 2018
Commented: Ameer Hamza
on 30 Apr 2018
For instance, I might use the following set command in the base workspace of some gui application:
set([someuiname.sl,someuiname.ed,someuiname.rb],'callback',{@somefunction,someuiname});
As I understand how this works, every time the gui slider, edit box, or radio button is changed the set command calls the function "somefunction" to execute. The input to "somefunction" is the entire gui structure "someuiname", and upon execution the entire gui gets updated. My question concerns the possibility of having multiple inputs into "somefunction." Suppose "somefunction" requires additional inputs, i.e. one or more structures (independent of the gui structure "someuiname"), arrays, or other data for execution. This could be the case, for example with a simulation, when a data structure needs to be updated along with the gui everytime a gui element is changed. I might think the following syntax could work for this purpose:
set([someuiname.sl,someuiname.ed,someuiname.rb],'callback',{@somefunction,someuiname,...someway to list additional data inputs?});
Maybe pointers to the additional data inputs need to be setup and incorporated into the set command? If so, how?
0 Comments
Accepted Answer
Ameer Hamza
on 29 Apr 2018
Although you can always resort to global variables or using evalin() and assignin(), to directly manipulate any data in a workspace, without actual need to pass and return. But these practices and highly unrecommended and only use for small projects when you actually know what you are trying to do.
For a proper solution, here is one way you can achieve what you are trying to do. You actually want to pass the extra input variables by reference. In MATLAB handle classes exhibit this behavior. All variables to a handle object will point to the same memory location and if one of them is modified, every other will show the change. You need to define your own handle class, with data properties as you want. Then create variables of your class and pass them to callback functions as input. When they change inside the callback, the actual copy will change too.
4 Comments
More Answers (0)
See Also
Categories
Find more on Function Creation 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!