Loop through parents name

14 visualizaciones (últimos 30 días)
Alexis
Alexis el 26 de Ag. de 2022
Comentada: Rik el 26 de Ag. de 2022
Hi all,
I'm trying to create a ui-generating function that is called several time instead of raw-coding every tab / button ... of every section of my interface.
To do it, I need to call this function for different tabs, ie different parents.
For example I have this kind of code :
obj.Display.Compare_Options = uicontrol(obj.Display.Panel_Perfo,'style','check','unit','normalized'); %shortened compared to real code
Where
  • obj.Display.PanelPerfo is a uitab
  • obj.Display.Compare_Options is a struct
And I'd like to be able to refer to different ui tab, as if I had something like :
uitabname = Panel_Perfo
obj.Display.Compare_Options = uicontrol (obj.Display.uitabname,'style','check','unit','normalized')
But when I do this, I have the error "Reference to non-existent filed 'uitabname' because MATLAB is searching for
obj.Display.uitabname
Where I want it to search for
obj.Display.Panel_Perfo
In order to change tab name based on callback source.
How can I make this happen ? Thanks !

Respuesta aceptada

Rik
Rik el 26 de Ag. de 2022
Editada: Rik el 26 de Ag. de 2022
If you're using a struct, you need to do this:
uitabname = 'Panel_Perfo';
obj.Display.Compare_Options = uicontrol(obj.Display.(uitabname),...
'Style','check',...
'Unit','Normalized')
If obj.Display is an object, you probably need to use get.
  2 comentarios
Alexis
Alexis el 26 de Ag. de 2022
obj.Display.(uitabname) works exactly how I wanted !
Thanks a lot !
Rik
Rik el 26 de Ag. de 2022
You're welcome. I prefer to use line continuations to break up long lines of code and easily spot which parameter has which value. You may want to consider a similar style.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by