What is the syntax for using multiple inputs for a callback function within a gui set command?

6 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 29 de Abr. de 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 comentarios
phillip stallworth
phillip stallworth el 30 de Abr. de 2018
Thank you for this example.....opens a few doors of understanding (i.e. use of classdef).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by