Main Content

findall

すべてのグラフィックス オブジェクトの検索

説明

h = findall(objhandles) は、objhandles のグラフィックス オブジェクトと、その子孫をすべて返します。関数 findobj とは異なり、findallHandleVisibility プロパティが 'off' に設定されている場合でもオブジェクトを返します。

h = findall(objhandles,prop1,value1,...,propN,valueN) は、指定したプロパティが指定した値に設定されている階層内のすべてのオブジェクトのハンドルを返します。たとえば、h = findall(gcf,'Type','text','Color','r') は、現在の Figure 内にある赤色の text オブジェクトをすべて返します。

すべて折りたたむ

3 つの Figure を作成します。最後の Figure の HandleVisibility プロパティを 'off' に設定します。

f1 = figure;
f2 = figure;
f3 = figure('HandleVisibility','off');

グラフィックス オブジェクト階層にある表示または非表示のハンドルの数を表示します。実際の結果は、表示されている結果と異なる場合があります。

h1 = findall(groot);
disp(numel(h1))
     4

表示または非表示のすべての Figure を検索します。

h2 = findall(groot,'Type','figure')
h2 = 
  3x1 Figure array:

  Figure    (3)
  Figure    (2)
  Figure    (1)

関数 findobj を使用して Figure を検索しようとすると、MATLAB® では f1f2 のみが返されます。

h3 = findobj('Type','figure')
h3 = 
  2x1 Figure array:

  Figure    (2)
  Figure    (1)

Figure 内の Text オブジェクトには非表示のハンドルがあります。findall を使用してこれらの非表示のハンドルを返します。

プロットをもつ Figure を作成します。次に、x 軸のラベルを作成します。

plot(1:10)
txt = xlabel('My x-axis label');

Figure contains an axes object. The axes object with xlabel My x-axis label contains an object of type line.

txtHandleVisibility プロパティが 'off' に設定されていることを確認します。

txt.HandleVisibility
ans = 
'off'

findall を使用して x 軸ラベルの Text オブジェクトを返します。

h1 = findall(gcf,'Type','text')
h1 = 
  Text (My x-axis label) with properties:

                 String: 'My x-axis label'
               FontSize: 11
             FontWeight: 'normal'
               FontName: 'Helvetica'
                  Color: [0.1500 0.1500 0.1500]
    HorizontalAlignment: 'center'
               Position: [5.5000 0.4452 -1.0000]
                  Units: 'data'

  Use GET to show all properties

Text オブジェクトは非表示であるため、関数 findobj を使用して検索できません。

h2 = findobj(gcf,'Type','text')
h2 = 
  0x0 empty GraphicsPlaceholder array.

findall を使用して、すべての Text オブジェクトまたは特定のプロパティをもつ Text オブジェクトを返します。

プロットをもつ Figure を作成します。次に、座標軸にラベルを付け、その座標軸にタイトルを加えます。タイトルの色を青に設定します。

plot((1:10).^2)
xlabel('x')
ylabel('y')
title('y = x^2','Color','b')

Figure contains an axes object. The axes object with title y = blank x Squared baseline, xlabel x, ylabel y contains an object of type line.

現在の Figure 内にあるすべての Text オブジェクトを返します。

h1 = findall(gcf,'Type','text')
h1 = 
  3x1 Text array:

  Text    (y = x^2)
  Text    (x)
  Text    (y)

次に、青色の Text オブジェクトをすべて返します。

h2 = findall(gcf,'Type','text','Color','b')
h2 = 
  Text (y = x^2) with properties:

                 String: 'y = x^2'
               FontSize: 11
             FontWeight: 'bold'
               FontName: 'Helvetica'
                  Color: [0 0 1]
    HorizontalAlignment: 'center'
               Position: [5.5000 100.7725 0]
                  Units: 'data'

  Use GET to show all properties

入力引数

すべて折りたたむ

検索対象のオブジェクト。グラフィックス オブジェクトの配列として指定します。findall は入力配列 objhandles 内のオブジェクトと、グラフィックス オブジェクト階層内のそのすべての子孫を検索します。

例: h = findall(groot) は、グラフィックス オブジェクト階層にある表示および非表示のすべてのハンドルを返します。

プロパティ名。文字ベクトルまたは string スカラーとして指定します。詳細については、グラフィックス オブジェクトのプロパティを参照してください。

例: h = findall(gcf,'Type','text') は、現在の Figure 内で Type プロパティが 'text' に設定されているすべてのオブジェクトを返します。

プロパティ値。スカラーまたは配列として指定します。

ヒント

  • findall による検索をカスタマイズするには、objhandles の後に関数 findobj の入力の組み合わせを使用します。以下に例を示します。

    h = findall(groot,prop1,value1,'-not',prop2,value2,'-property',prop3)
    

バージョン履歴

R2006a より前に導入