Class: handle

Find handle objects


Hmatch = findobj(H)
Hmatch = findobj(H,property,value,...,property,value)
Hmatch = findobj(H,'-not',property,value)
Hmatch = findobj(H,'-regexp',property,value)
Hmatch = findobj(H,property,value,'-logicaloperator',property,value)
Hmatch = findobj(H,'-function',fh)
Hmatch = findobj(H,'-function',property,fh)
Hmatch = findobj(H,'-property',property)
Hmatch = findobj(H,'-method',methodname)
Hmatch = findobj(H,'-event',eventname)
Hmatch = findobj(H,'-depth',d,___)
Hmatch = findobj(H,'flat',___)


Hmatch = findobj(H) returns the objects listed in H and all of their descendants.

Hmatch = findobj(H,property,value,...,property,value) finds handle objects that have the specified property set to the specified value.

Hmatch = findobj(H,'-not',property,value) inverts the expression in the following property value pair. That is, find objects whose specified property is not equal to value.

Hmatch = findobj(H,'-regexp',property,value) treats the content of the value argument as regular expressions.

Hmatch = findobj(H,property,value,'-logicaloperator',property,value) applies the logical operator to the name/value pairs. Supported logical operators include:

  • '-or' (default if you do not specify an operator)

  • '-and'

  • '-xor'

Hmatch = findobj(H,'-function',fh) calls the function handle fh on the objects in H and returns the objects for which the function returns true.

Hmatch = findobj(H,'-function',property,fh) calls the function handle fh on the specified property's value for the objects in H and returns the objects for which the function returns true. The function must return a scalar logical value.

Hmatch = findobj(H,'-property',property) finds all object in H having the named property.

Hmatch = findobj(H,'-method',methodname) finds objects that have the specified method name.

Hmatch = findobj(H,'-event',eventname) finds objects that have the specified event name.

Hmatch = findobj(H,'-depth',d,___) specifies how many levels in the instance hierarchies under the objects in H to search.

Hmatch = findobj(H,'flat',___) searches only the level of the objects in array H.


  • findobj has access only to public properties

  • If there are no matches, findobj returns an empty array of the same class as the input array H.

  • Logical operator precedence follows MATLAB® precedence rules. For more information, see Operator Precedence.

  • Control precedence by grouping within cell arrays

Input Arguments

expand all

H — Objects to search fromhandle array

Objects to search from, specified as an array of object handles. Unless the you specify the '-depth' or 'flat' options, findobj searches the objects in the input array H and child objects in the instance hierarchy.

property — Property namestring

Property name, specified as a case-sensitive, quoted string.

value — Property valueany value

Property value, specified as a value or MATLAB expression.

methodname — Method namestring

Method name, specified as a case-sensitive quoted string.

eventname — Event namestring

Event name, specified as a case-sensitive quoted string.

d — Depth of searchinteger >= 0

Depth of search, specified as an integer indicating the number of levels below any given object in the input array H.

  • d = n — Search n levels of the hierarchy below each object in H

  • d = 0 — Search only the same level as the objects in H.

  • d = inf — Search all levels below objects in H. This is the default.

fh — Function handlefunction handle

Function handle, specifying the function that is evaluated for each object in the input array H. This function must return a scalar, logical value indicating whether there is a match (true) or not (false).

Output Arguments

expand all

Hmatch — Objects found by searchhandle array

Objects found by search, returned as a handle array.



To learn about attributes of methods, see Method Attributes in the MATLAB Object-Oriented Programming documentation.


Object with Specific Property Value

Find the object with a specific property value. Given the handle class, BasicHandle:

classdef BasicHandle < handle
      function obj = BasicHandle(val)
         if nargin > 0
            obj.Prop1 = val;

Create an array of BasicHandle objects:

h(1) = BasicHandle(7);
h(2) = BasicHandle(11);
h(3) = BasicHandle(27);

Find the handle of the object whose Prop1 property has a value of 7:

h7 = findobj(h,'Prop1',7);
ans =


Object with Specific Property Name

Find the object with a specific dynamic property. Given the button class:

classdef button < dynamicprops
      function obj = button(pos)
         if nargin > 0
            if length(pos) == 4
               obj.UiHandle = uicontrol('Position',pos,...
               error('Improper position')

Create an array of button objects, only one element of which defines a dynamic property. Use findobj to get the handle of the object with the dynamic property named ButtonCoord:

b(1) = button([20 40 80 20]);
b(1).ButtonCoord = [2,3];
b(2) = button([120 40 80 20]);
b(3) = button([220 40 80 20]);

h =  findobj(b,'-property','ButtonCoord');
ans =

     2     3

See Also

Was this topic helpful?