Main Content

ancestor

グラフィックス オブジェクトの上位オブジェクト

構文

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

説明

p = ancestor(h,type) は、h の最も近い先祖が type で指定されているグラフィックス オブジェクトのいずれかのタイプである場合に、その先祖のハンドルを返します。type は以下のいずれかです。

  • 1 つのオブジェクト タイプの名前をもつ文字ベクトル。たとえば、'figure'

  • 複数のオブジェクトの名前を含む cell 配列。たとえば、{'hgtransform','hggroup','axes'}

MATLAB® が、指定タイプのいずれかである h の上位オブジェクトを検出できない場合、ancestor は空の p を返します。ancestor が階層を検索する場合、オブジェクト自体が検索に含まれます。したがって、ハンドル h があるオブジェクトが type にリストされているいずれかのタイプである場合、ancestorh オブジェクトを返します。

ancestor は空の p を返しますが、h がグラフィックス オブジェクトでない場合はエラーを発行しません。

p = ancestor(h,type,'toplevel') は、このタイプが type 引数で指定されている場合、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 より前に導入

参考