How can I find an uifigure?

I am mixing some old GUIs designed with GUIDE with uifigures, so I can use the uitree object (and some others).
However, when I try to establish communication between some functions in my GUIs (need to click on an ax and then assign some value from a tree node and insert into a table) I cannot find the uifigure - neither using "findobj ('Type', 'figure')" nor using "findall (groot)". Before I started this design I did not even consider this possibility, thought it would be something quite simple - which it probably is but I cannot get past this point.
Would really appreciate any answer or a possible solution to this issue.

6 Comments

I am able to create a figure using uifigure and then find the handle using findall(groot) using R2019b. Have you tried assigning a name to the figure during creation? If not, it might be worth a try to see if you are not locating it simply because it is hard to identify amoung a list of Figures when using findall.
uifigure('Name','YourFigureName')
Thanks to everyone for your hep. However the problem is more complicated - I had already tried searching with both Type, Tag, etc. I forgot to mention about the handle visibility (see Walter‘s answer) but it cannot be set to ON if - almost unbelievable! - the uifigure was created using the uifigure function, which is here the case. I am expecting an answer from Mathworks about this case.
Have you tried findall without the tag? That should work with uifigures / appdesigner.
I had no problem using
H = uifigure('handlevisibility', 'on')
when I tested.
Walter - thanks! But I get this err msg:
" Error using appwindowfactory
Functionality not supported with figures created with the uifigure function. For more information, see
Graphics Support in App Designer. "
Problem is that right now I must use figures as I am adapting some existing code and must try to avoid opening a new window as much as possible. Cannot use the appdesigner in this case without adding some substantial amount of work...
Adam Danz
Adam Danz on 26 Jan 2020
Edited: Adam Danz on 26 Jan 2020
In r2019b the handlevisibility property of uifigures can only be set to off.
When it's set to "on" you get a "functionality not supported" error. Maybe that will change in 2020a.

Sign in to comment.

 Accepted Answer

Adam Danz
Adam Danz on 26 Jan 2020
Edited: Adam Danz on 27 Jan 2020
You can find the uifigure handle using findall() but it's not recommended to merely find handles to all figures because it's quite likely that at some point other figures will exist other than your GUI.
To find the handle to your GUI figure, add a long, descriptive, unique name to the tag property of your GUI. Then specify that unique tag name when searching for the GUI handle.
uif = uifigure('Tag','MyUniqueTag'); % a demo ui-figure with a unique tag name
h = findall(0,'Type','figure','tag','MyUniqueTag') % Get the handle.
To search for all figures (hidden or not)
h = findall(0,'Type','figure');

More Answers (2)

If you create the uifigure with HandleVisibility, 'on', then you can
findobj(groot, 'type', 'figure')
otherwise you need findall() because the handle visibility for uifigure defaults to 'off'
Clovis Bonavides
Clovis Bonavides on 28 Jan 2020
None of the solutions proposed up to this point does work. The visibility of the uifigure created programmatically cannot be set to ON - which is probably a bug. Hopefully this will be fixed in the next coming version. Anyway, many thanks to all those who tried to help me. I actually got around by working creating a new window with the uifigure (tree), something I much wanted to avoid.

3 Comments

Adam Danz
Adam Danz on 28 Jan 2020
Edited: Adam Danz on 28 Jan 2020
My answer absolutely works in r2019b (the release you're using).
% Create a UIFigure
uif = uifigure('Name','ThisWorks!');
% Find handles to all figures
h = findall(0,'Type','figure')
Result
h =
Figure (ThisWorks!) with properties:
Number: []
Name: 'ThisWorks!'
Color: [0.9400 0.9400 0.9400]
Position: [508 656 583 437]
Units: 'pixels'
Show all properties
If it doesn't work for you then something else is wrong.
Adam Danz
Adam Danz on 28 Jan 2020
Edited: Adam Danz on 28 Jan 2020
Clovis Bonavides's answer moved here as a comment
Adam, you are absolutely correct. It DOES work in vers 2019.b, which I just got loaded.
In vers 2018b it doesn't work as the uifigure's handle visibility is "hardwired" to "OFF" and cannot be changed through the uifigure generation code.
Thanks!
On the right hand column of this page you can see the Product and Release fields where you entered r2019b. This is very helpful info and most people don't fill it out (so, thank you!).
BTW, I just tested the lines in my comment above in r2018b and it also works there, too. Maybe something was copied wrong when you were trying it out.

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!