Documentation Center

  • Trial Software
  • Product Updates
라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

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 string that is 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 the handle of a Handle 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

Was this topic helpful?