This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Locate graphics objects with specific properties


h = findobj
h = findobj('PropertyName',PropertyValue,...)
h = findobj('PropertyName',PropertyValue,'-logicaloperator', PropertyName',PropertyValue,...)
h = findobj('-regexp','PropertyName','regexp',...)
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','regexp',...) matches objects using regular expressions as if the value of you passed the property PropertyName to the regexp function as

If a match occurs, findobj returns the object handle. See the regexp function for information on how the MATLAB® software uses regular expressions.

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.

To find handle objects that meet specified conditions, use findobj.


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

Related Examples

See Also

| | | | | | | | |

Introduced before R2006a

Was this topic helpful?