I created a variable GUI function with several objects without variable names, how can I access their handles??
Ältere Kommentare anzeigen
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 Kommentare
Stephen23
am 25 Jul. 2018
"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
am 25 Jul. 2018
Stephen23
am 25 Jul. 2018
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
am 25 Jul. 2018
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!