GUI - using "handles.tag" with variable tag

2 visualizaciones (últimos 30 días)
Pollok Tim
Pollok Tim el 1 de Mayo de 2016
Respondida: Walter Roberson el 1 de Mayo de 2016
Hi everybody,
I used GUIDE to built a GUI with several axes taged as data1,data2,data3,... In the opening function I use
set(handles.tagsofallaxes,'visible','off');
to display them all.
Now I inserted checkboxes which get a unique plot and place this plot in the next free axes. For example: first plot in data1, second in data2, maybe I uncheck afterwards the checkbox for plot1 and data1 will be free again. when I check for plot 3 after this, it should appear in data1 which was empty at this moment.
For this I coded a function that gives me the next free axes. Output of the function is a string (data1,data2,data3,...).
I don't get how I can use the output to show my plot on the axes.
nextfreeaxes = counter('position'); % saves tag of next free axes in string
axes(handles.nextfreeaxes)
gives error: Reference to non-existent field 'nextfreeaxes'.
When I build a switch case everything is fine. But its not the way I want to do this.
nextfreeaxes = counter('position'); % saves tag of next free axes in string
switch nextfreeaxes
case 'data1'
axes(handles.data1)
case 'data2'
axes(handles.data2)
case 'data3'
axes(handles.data3)
case 'data4'
axes(handles.data4)
end
I know that handles is a struct, but I don't get how to have access to its parts in the way I need it. I am a beginner in coding so please help me.

Respuesta aceptada

Walter Roberson
Walter Roberson el 1 de Mayo de 2016
handles.(nextfreeaxes)
However, I suggest that you just create a vector of all of the values,
axhandles = [handles.data1, handles.data2, handles.data3];
Then you can index them
axes(axhandles(idx))

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by