Documentation

This is machine translation

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

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

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 of h, if the ancestor is one of the types of graphics objects specified by type. type can 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 of h that is one of the specified types, then ancestor returns p as empty. When ancestor searches the hierarchy, it includes the object itself in the search. Therefore, if the object with handle h is of one of the types listed in type, ancestor will return object h.

ancestor returns p as empty but does not issue an error if h is not a graphics object.

p = ancestor(h,type,'toplevel') returns the highest-level ancestor of h, if this type appears in the type argument.

Examples

Find the ancestors of a line object:

% Create some line objects and parent them 
% to an hggroup object.
hgg = hggroup;
hgl = line(randn(5),randn(5),'Parent',hgg);
% Now get the ancestor of the lines:
p = ancestor(hgg,{'figure','axes','hggroup'});
get(p,'Type')
% Now get the top-level ancestor: 
ptop=ancestor(hgg,{'figure','axes','hggroup'},'toplevel');
get(ptop,'type')

See Also

Introduced before R2006a

Was this topic helpful?