I created a variable GUI function with several objects without variable names, how can I access their handles??
古いコメントを表示
Here's a sample of the code. This code gets opened after pressing a button and accepting input(variable n) from a gui I created using GUIDE. Now that I have this variable gui that creates several editable text boxes, I need to access the results after they get placed inside and press another button. These objects were created without variable names, is there still a way to access them? Or did I reach a dead end and have to create something else? Thank you in advance!!
if n<10
for i=2:n
numberText=num2str(i);
uicontrol('Style','edit','Position',[nPos(1), (nPos(2)-(25*(i-1))), nPos(3), nPos(4)]);
uicontrol('Style','text','Position',[nTextPos(1), (nTextPos(2)-(25*(i-1))), nTextPos(3), nTextPos(4)],'String',("HV"+numberText),'FontSize',12,'BackgroundColor',[0.2 0.2 0.2],'ForegroundColor','w');
end
elseif n>=10
for i=2:9
numberText=num2str(i);
uicontrol('Style','edit','Position',[nPos(1), (nPos(2)-(25*(i-1))), nPos(3), nPos(4)]);
uicontrol('Style','text','Position',[nTextPos(1), (nTextPos(2)-(25*(i-1))), nTextPos(3), nTextPos(4)],'String',("HV"+numberText),'FontSize',12,'BackgroundColor',[0.2 0.2 0.2],'ForegroundColor','w');
end
for i=10:n
numberText=num2str(i);
uicontrol('Style','edit','Position',[nPos(1), (nPos(2)-(25*(i-1))), nPos(3), nPos(4)]);
uicontrol('Style','text','Position',[nTextPos(1)-8, (nPos(2)-(25*(i-1))), nTextPos(3)+8, nTextPos(4)],'String',("HV"+numberText),'FontSize',12,'BackgroundColor',[0.2 0.2 0.2],'ForegroundColor','w');
end
end
4 件のコメント
Stephen23
2018 年 7 月 25 日
"These objects were created without variable names, is there still a way to access them?"
Not without writing a lot of code. The best solution by far is to always explicitly allocate all graphics handles and then use them for accessing those objects. This makes your code simpler, easier to understand, and less buggy.
MechE1
2018 年 7 月 25 日
Stephen23
2018 年 7 月 25 日
I mean allocate the output of the function that creates the graphics object to a variable, e.g.:
fgh = figure(...);
or in a loop:
for k = ...
axh(k) = axes(...);
end
then you can trivially access any graphics object that you create.
MechE1
2018 年 7 月 25 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!