GUI - using "handles.tag" with variable tag

1 回表示 (過去 30 日間)
Pollok Tim
Pollok Tim 2016 年 5 月 1 日
回答済み: Walter Roberson 2016 年 5 月 1 日
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.

採用された回答

Walter Roberson
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 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by