findall
查找所有图形对象
说明
h = findall(
返回 objhandles
)objhandles
中的图形对象及其所有后代。与 findobj
函数不同,findall
会返回对象,即使其 HandleVisibility
属性设置为 'off'
也是如此。
示例
查找具有可见或隐藏句柄的图窗
创建三个图窗。将最后一个图窗的 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® 只返回 f1
和 f2
。
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' Show all properties
由于 Text
对象是隐藏的,您无法使用 findobj
函数找到它。
h2 = findobj(gcf,'Type','text')
h2 = 0x0 empty GraphicsPlaceholder array.
查找 Text 对象
使用 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' Show all properties
输入参数
objhandles
— 要从中搜索的对象
图形对象数组
要从中搜索的对象,指定为图形对象的数组。findall
在图形对象层次结构中搜索输入数组 objhandles
中的对象及其所有后代。
示例: h = findall(groot)
返回图形对象层次结构中所有可见和隐藏的句柄。
prop
— 属性名称
字符向量 | 字符串标量
属性名称,指定为字符向量或字符串标量。有关详细信息,请参阅图形对象属性。
示例: h = findall(gcf,'Type','text')
返回当前图窗中 Type
属性设置为 'text'
的所有对象。
value
— 属性值
标量 | 数组
属性值,指定为标量或数组。
提示
要使用
findall
自定义您的搜索,您可以使用objhandles
,然后使用findobj
函数的输入组合。例如:h = findall(groot,prop1,value1,'-not',prop2,value2,'-property',prop3)
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)