Locate graphics objects with specific properties


h = findobj
h = findobj('PropertyName',PropertyValue,...)
h = findobj('PropertyName',PropertyValue,'-logicaloperator', 'PropertyName',PropertyValue,...)
h = findobj('-regexp','PropertyName','expression',...)
h = findobj('-property','PropertyName')
h = findobj(objhandles,...)
h = findobj(objhandles,'-depth',d,...)
h = findobj(objhandles,'flat','PropertyName',PropertyValue,...)


findobj returns handles of the root object and all its descendants without assigning the result to a variable.

h = findobj returns handles of the root object and all its descendants.

h = findobj('PropertyName',PropertyValue,...) returns handles of all graphics objects having the property PropertyName, set to the value PropertyValue. You can specify more than one property/value pair, in which case, findobj returns only those objects having all specified values.

h = findobj('PropertyName',PropertyValue,'-logicaloperator', 'PropertyName',PropertyValue,...) applies the logical operator to the property value matching. Possible values for -logicaloperator are:

  • -and

  • -or

  • -xor

  • -not

For more information on logical operators, see Logical Operations.

h = findobj('-regexp','PropertyName','expression',...) matches objects by evaluating the specified regular expression using the value of the specified property. Objects with property values satisfying the regular expression are returned.

h = findobj('-property','PropertyName') finds all objects having the specified property.

h = findobj(objhandles,...) restricts the search to objects listed in objhandles and their descendants.

h = findobj(objhandles,'-depth',d,...) specifies the depth of the search. The depth argument d controls how many levels under the handles in objhandles MATLAB® traverses. Specify d as inf to get the default behavior of all levels. Specify d as 0 to get the same behavior as using the flat argument.

h = findobj(objhandles,'flat','PropertyName',PropertyValue,...) restricts the search to those objects listed in objhandles and does not search descendants.

findobj returns an error if a handle refers to a nonexistent graphics object.

findobj correctly matches any legal property value. For example,

finds all objects having a Color property set to red, r, or [1 0 0].

When a graphics object is a descendant of more than one object identified in objhandles, MATLAB searches the object each time findobj encounters its handle. Therefore, implicit references to a graphics object can result in multiple returns of its handle.


findobj does not return graphics objects that have the HandleVisibility property set to 'off'. For more information, see the HandleVisibility property description.


Find all line objects in the current axes:

h = findobj(gca,'Type','line')

Find all objects having a Label set to 'foo' and a String property set to 'bar':

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

Find all objects whose String property is not 'foo' and is not 'bar':

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

Find all objects having a String property set to 'foo' and a Tag property set to 'button one' and whose Color property is not 'red' or 'blue':

h = findobj('String','foo','-and','Tag','button one',...

Find all objects for which you have assigned a value to the Tag property (that is, the value is not the empty character vector ''):

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])

See Also

| | | | | | | | |

Introduced before R2006a