GUI - using "handles.tag" with variable tag

3 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 1 May 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))

More Answers (0)

Community Treasure Hunt

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

Start Hunting!