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!