Main Content

findall

查找所有图形对象

说明

示例

h = findall(objhandles) 返回 objhandles 中的图形对象及其所有后代。与 findobj 函数不同,findall 会返回对象,即使其 HandleVisibility 属性设置为 'off' 也是如此。

示例

h = findall(objhandles,prop1,value1,...,propN,valueN) 返回层次结构中指定属性设置为指定值的所有对象的句柄。例如,h = findall(gcf,'Type','text','Color','r') 返回当前图窗中的所有红色文本对象。

示例

全部折叠

创建三个图窗。将最后一个图窗的 HandleVisibility 属性设置为 'off'

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

显示图形对象层次结构中可见或隐藏句柄的数量。您的结果可能与所示的结果不同。

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

找到所有可见或隐藏的图窗。

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

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

如果您尝试使用 findobj 函数查找图窗,MATLAB® 只返回 f1f2

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

  Figure    (2)
  Figure    (1)

图窗中的 Text 对象具有隐藏的句柄。使用 findall 返回这些隐藏的句柄。

用 plot 创建一个图窗。然后,为 x 轴创建一个标签。

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

验证 txt 上的 HandleVisibility 属性已设置为 '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 对象。

用 plot 创建一个图窗。然后,对坐标区加标签并向坐标区添加标题。将标题的颜色设置为蓝色。

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

返回当前图窗中的所有 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) 返回图形对象层次结构中所有可见和隐藏的句柄。

属性名称,指定为字符向量或字符串标量。有关详细信息,请参阅图形对象属性

示例: h = findall(gcf,'Type','text') 返回当前图窗中 Type 属性设置为 'text' 的所有对象。

属性值,指定为标量或数组。

提示

  • 要使用 findall 自定义您的搜索,您可以使用 objhandles,然后使用 findobj 函数的输入组合。例如:

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

版本历史记录

在 R2006a 之前推出