Graphics    

Searching for Objects by Property Values -- findobj

The findobj function provides a means to traverse the object hierarchy quickly and obtain the handles of objects having specific property values. If you do not specify a starting object, findobj searches from the root object, finding all occurrences of the property name/property value combination you specify.

Example -- Finding Objects

This plot of the sine function contains text objects labeling particular values of function.

Suppose you want to move the text string labeling the value sin(t) = .707 from its current location at [pi/4,sin(pi/4)] to the point [3*pi/4,sin(3*pi/4)] where the function has the same value (shown grayed out in the picture). To do this, you need to determine the handle of the text object labeling that point and change its Position property.

To use findobj, pick a property value that uniquely identifies the object. In this case, the text String property.

Next move the object to the new position, defining the text Position in axes units.

findobj also lets you restrict the search by specifying a starting point in the hierarchy, instead of beginning with the root object. This results in faster searches if there are many objects in the hierarchy. In the previous example, you know the text object of interest is in the current axes so you can type


  The Current Figure, Axes, and Object Copying Objects