Main Content

ancestor

Ancestor of graphics object

Syntax

p = ancestor(h,type)
p = ancestor(h,type,'toplevel')

Description

p = ancestor(h,type)returns the handle of the closest ancestor ofh, if the ancestor is one of the types of graphics objects specified bytype.typecan be:

  • a character vector with the name of a single type of object, for example,'figure'.

  • a cell array containing the names of multiple objects, for example,{'hgtransform','hggroup','axes'}.

If MATLAB®cannot find an ancestor ofhthat is one of the specified types, thenancestorreturnspas empty. Whenancestorsearches the hierarchy, it includes the object itself in the search. Therefore, if the object with handlehis of one of the types listed intype,ancestorwill return objecth.

ancestorreturnspas empty but does not issue an error ifhis not a graphics object.

p = ancestor(h,type,'toplevel')returns the highest-level ancestor ofh,如果这类型中出现typeargument.

Examples

collapse all

CreateLineobjects and parent them to aGroupobject. Then return the top-level ancestor.

g = hggroup; ln = line(randn(5),randn(5),'Parent',g);

Figure contains an axes object. The axes object contains 5 objects of type line.

tp = ancestor(g,{'figure','axes','hggroup'},'toplevel')
tp = Figure (1) with properties: Number: 1 Name: '' Color: [1 1 1] Position: [348 480 583 437] Units: 'pixels' Show all properties

Version History

Introduced before R2006a

See Also