Matlab之findobj()


findobj

findobj:特殊屬性的圖形對象

 

語法:

1.findobj:

findobj返回根對象的句柄和所有子對象(findobj returns handles of the root object and all its descendants without assigning the result to a variable.)


2.h = findobj:

返回根對象的句柄和所有子對象


3.h = findobj('PropertyName',PropertyValue,...)

返回所有屬性名為‘PropertyName’,屬性值為'PropertyValue'的圖形對象的句柄。可以指定多個屬性/值對。


4.h = findobj('PropertyName',PropertyValue,'-logicaloperator', PropertyName',PropertyValue,...)

 

-logicaloperator可以取值:

-and

-or

-xor

-not


5.h = findobj('-regexp','PropertyName','regexp',...)

屬性名可以使用正則表達式

6.h = findobj('-property','PropertyName')

如果存在‘PropertyName’這個屬性名,就返回此圖形句柄

7.h = findobj(objhandles,...)

限制搜索范圍為objhandles和他們的子圖中


8.h = findobj(objhandles,'-depth',d,...)

指定搜索深度,深度參數'd'控制遍歷層數,d為inf表示遍歷所有層,d為0等同d='flat'


9.h = findobj(objhandles,'flat','PropertyName',PropertyValue,...)

 'flat'限制搜索范圍只能是當前層,不能搜索子圖。

如果句柄指向一個不存在的圖形,findobj返回一個錯誤。

findobj正確匹配任何合法屬性值,例如:

findobj('Color','r')

找到所有color值為紅的對象。

為了尋找滿足指定條件的額handle對象,我們可以使用handle.findobj。

 

例子:

在當前坐標下查找所有直線對象:
h = findobj(gca,'Type','line')  %gca為當前坐標的句柄
 

查找Label屬性設為'foo'和String設為'bar'的所有對象:
h = findobj('Label','foo','-and','String','bar');
 

查找String不為'foo'也不為'bar'的所有對象:

h = findobj('-not','String','foo','-not','String','bar');
 

h = findobj('String','foo','-and','Tag','button one',...
 '-and','-not',{'Color','red','-or','Color','blue'})
 

Find all objects for which you have assigned a value to the Tag property (that is, the value is not the empty string ''):
h = findobj('-regexp','Tag','[^'']')
 

Find all children of the current figure that have their BackgroundColor property set to a certain shade of gray ([.7 .7 .7]). This statement also searches the current figure for the matching property value pair.
h = findobj(gcf,'-depth',1,'BackgroundColor',[.7 .7 .7])


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM