Having trouble with guide, tags, and Findobj

15 views (last 30 days)
Steven
Steven on 8 Nov 2012
Answered: Feng Cheng on 10 Jun 2018
I have a situation that has me pulling out what little hair I have left. In the past, I have used findobj() to help me find handle graphics objects with unique tags. I am trying to get this to work on some new code and it is just failing, and I can't figure out why. I know I am missing something obvious, but it's been a while since I used findobj().
The story is this. I am using GUIDE to create a figure, which will then have buttons and such on it. I use the Property Inspector within Guide to call up the properties of the figure, change the background color, re-name it, and give it a tag, let's call it "Census." I then save the GUI as a .fig and .m. Now when I execute this figure, it should have the property "Tag" set to "Census". And if I use the figure tools to examine the properties, this is indeed the case.
Yet, if I do p = findobj('Tag', 'Census'), matlab returns an empty matrix.
I thought perhaps the syntax of findobj had changed, but I have some code from years ago that does exactly the same thing (tag was set originally in Guide) and when I execute the command for that window in exactly the same way, and use findobj the same way, matlab returns a figure number (which is, of course, what I want).
Anyone have any idea what is going on? I am frankly stumped. This should be a simple thing, and it works with my old code perfectly, yet the exact same thing does not work with my new figure. I've been trying to get this simple thing to work all afternoon, and now I am just frustrated beyond belief. Any help would be appreciated.

Answers (2)

Matt Fig
Matt Fig on 8 Nov 2012
Edited: Matt Fig on 8 Nov 2012
GUIDE GUIs have hidden handles...
p = findall(0,'tag','Census')
P.S., you may want to switch to other methods of handle retrieval than these, such as GUIDATA. Also, you are running the GUI by calling the m-file, not by opening the figure, correct?
  3 Comments
Matt Fig
Matt Fig on 8 Nov 2012
Edited: Matt Fig on 8 Nov 2012
Give this a try.
Run the GUI that is giving you trouble by asking for the handle.
H = mygui; % For example.
get(get(H,'children'),'tag')
This will show you what the tags really are.
John
John on 14 Sep 2015
Edited: John on 14 Sep 2015
Hey guys,
I have the same problem as above! None of your options works Matt:( i really dont know whats the problem....
I have one MainGui and a SubGui that is opened by the user from the MainGui. Nevertheless i dont find SubGui when i search for children of MainGui. But i think i dont use the children function in a correct way. HOw can i do it? the tag 'try1_' is from my MainGui. I find this one but not the other one from SubGui.
H = findobj('Tag','try1_')
handlesH = guidata(H)
allchild(H)
i get this"
ans =
9.0033
8.0033
7.0033
6.0033
5.0033
0.0033
197.0032
195.0032
190.0032
188.0032
185.0032
183.0032
181.0032
174.0032
What is the problem? I am very glad for your help!
Best regards, John

Sign in to comment.


Feng Cheng
Feng Cheng on 10 Jun 2018
Hey guys,
Is this issue fixed? I think i have the same problem. The same code is really on again and off again. e.g., the following phrase sometime will throw out error 'Unable to perform assignment because the indices on the left side are not compatible with the size of the right side' because `findobj` return empty.
item = findobj(gcf, 'Tag', 'flow_listbox')
So i replace `findobj` with the following phrase. and it works well.
item = handles.flow_listbox
But i really want to know what's wrong with `findobj`.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!