GUI - using "handles.tag" with variable tag
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Walter Roberson
2016-5-1
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))
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!