findobj for multiple 'Tag's
13 次查看(过去 30 天)
显示 更早的评论
Hi, is there any way I could look for multiple tags like this:
findobj(0,'Tag',['Name1','Name2','Name3',etc])
instead of
findobj(0,'Tag','Name1','-or','Tag','Name2','-or','Tag','Name3'...etc)
????
Thank you
0 个评论
采纳的回答
Andrew Reibold
2013-6-17
编辑:Andrew Reibold
2013-6-17
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})
end
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 个)
per isakson
2013-6-17
编辑:per isakson
2013-6-17
A shot in the dark with R2012a. This returns handles rather than an error message
>> findobj(0,'Tag',{'Name1','Name2','Name3'} )
ans =
0
221.0011
220.0011
219.0011
218.0011
188.0011
156.0011
190.0011
189.0011
158.0011
157.0011
>>
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 =
''
''
''
''
''
''
''
''
''
''
''
2 个评论
Andrew Reibold
2013-6-17
编辑:Andrew Reibold
2013-6-17
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!