MATLAB: I created a variable GUI function with several objects without variable names, how can I access their handles?

callbackguihandlesmatlab gui

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

Best Answer

Option 1 Assign handles to the uicontrol outputs.
h(1) = uicontrol('Style','edit', ...);
Now you can access that object via its handle h(1) if you're accessing it within the code. However, if you're trying to access a GUI object outside of the code (say, from the command line) this solution will not work unless you have access to the handles.
Option 2 Assign a 'tag' to each object. A tag is a property where you can assign a string and name the object.
h(1) = uicontrol('Style','edit', ..., 'tag', 'editBox1');
If each object has a different tag, you can search for the object using findobj(). The first input should be the figure handle that contains the object you're searching for.
findobj(gcf, 'Tag', 'editBox1')
This will return the object's handle whether you saved the handle in h(1) or not. When using this method, you should be as specific as possible when entering the search parameters in findobj() in case there happens to be multiple objects with the same tag. For example, if you know the object is an 'edit' box,
findobj(gcf, 'Style', 'edit', 'Tag', 'editBox1')