Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

ancestor

图形对象的前代

语法

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

说明

如果前代是 type 指定的图形对象类型之一,则 p = ancestor(h,type) 返回 h 的最近前代的句柄。type 可以是:

  • 包含单个对象类型的名称的字符向量,例如 'figure'

  • 包含多个对象名称的元胞数组,例如 {'hgtransform','hggroup','axes'}

如果 MATLAB® 找不到 h 的某种指定类型的前代,则 ancestor 返回空的 pancestor 搜索层次结构时,它在搜索中包含对象本身。因此,如果具有句柄 h 的对象属于 type 中列出的类型之一,则 ancestor 将返回对象 h

如果 h 不是图形对象,则 ancestor 返回空的 p,但不引发错误。

如果此类型出现在 type 参数中,则 p = ancestor(h,type,'toplevel') 返回 h 的最高前代。

示例

全部折叠

创建 Line 对象并将它们作为 Group 对象的父级。然后返回顶层前代。

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 376 583 437]
       Units: 'pixels'

  Use GET to show all properties

版本历史记录

在 R2006a 之前推出

另请参阅