MATLAB Answers

Vincent I

findobj for multiple 'Tag's

Asked by Vincent I
on 17 Jun 2013

Hi, is there any way I could look for multiple tags like this:


instead of



Thank you




No products are associated with this question.

2 Answers

Answer by Andrew Reibold
on 17 Jun 2013
Edited by Andrew Reibold
on 17 Jun 2013
 Accepted answer

When you use findobj, it returns the object handle (May look like an arbitrary number to the user). There are many ways to do what you want I think. Here is one

First, create a cell array with the names of the tags you want to find, then use findobj in a loop to collect the object handles.

mytags = {'Name1' 'Name2' 'Name3' ... )
for i = length(mytags)
     objecthandles.(genvarname(mytags{1})= findobj(0, 'tag', mytags{1})

The output should be a structure of variables called 'objecthandles' that has variables for each of your tag names, and the variables store the object handles.

The output should look something like:

objecthandles = 
   objecthandles.Name1 = 300.12
   objecthandles.Name2 = 292.73
   objecthandles.Name3 = 512.42

You now are able to call all of their handles at will. Let me know if I made a syntax error or soemthing and I can correct this.

  1 Comment

Vincent I
on 18 Jun 2013

i was trying to limit using a loop to get the handle for each figure but i guess this is the only way to go. thanks for your answers

Answer by per isakson
on 17 Jun 2013
Edited by per isakson
on 17 Jun 2013

A shot in the dark with R2012a. This returns handles rather than an error message

    >> findobj(0,'Tag',{'Name1','Name2','Name3'} )
    ans =

Cell array would be the Matlab way. Compare set. However, I don't think it is covered by the documentation.

No good:

    >> h = findobj(0,'Tag',{'Name1','Name2','Name3'} );
    >> get( h, 'Tag' )
    ans = 


Andrew Reibold
on 17 Jun 2013

Nice! I think my answer was doing it the hard way.

Always better to use arrays/vectors than a loop whenever possible. It is much more resource efficient. Use this answer Victor

per isakson
on 17 Jun 2013

I'll file this as a request or bug:-)

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!