查找具有特定属性的图形对象 - MATLAB findobj (2024)

查找具有特定属性的图形对象

全页折叠

语法

h = findobj

h = findobj(prop,value)

h = findobj('-not',prop,value)

h = findobj(prop1,value1,oper,prop2,value2)

h = findobj('-regexp',prop,expr)

h = findobj('-property',prop)

h = findobj(prop1,value1,...,propN,valueN)

h = findobj(objhandles,___)

h = findobj(objhandles,'-depth',d,___)

h = findobj(objhandles,'flat',___)

说明

示例

h = findobj 返回图形根对象及其所有后代。

示例

h = findobj(prop,value) 返回层次结构中属性 prop 设置为 value 的所有对象。

示例

h = findobj('-not',prop,value) 返回其指定属性未设置为指定值的所有对象。

示例

h = findobj(prop1,value1,oper,prop2,value2) 将逻辑运算符 oper 应用于 prop,value 对组。例如,h = findobj('LineStyle','--','-and','Marker','o') 返回具有虚线线型和圆形标记的所有对象。

示例

h = findobj('-regexp',prop,expr) 使用正则表达式来查找具有特定属性值的对象。函数返回属性值满足正则表达式的对象。

示例

h = findobj('-property',prop) 返回具有指定属性的所有对象。

示例

h = findobj(prop1,value1,...,propN,valueN) 返回层次结构中指定属性设置为指定值的所有对象。您可以用上述语法中的其他输入参量组合替换 prop,value 对组。例如,h = findobj(prop1,value1,'-not',prop2,value2,'-property',prop3) 返回满足以下三个条件的所有对象:

  • 该对象的属性 prop1 设置为 value1

  • 该对象的属性 prop2 的值未设置为 value2

  • 该对象具有属性 prop3

示例

h = findobj(objhandles,___) 将搜索范围限制为在 objhandles 中列出的对象及其所有后代。您可以对任何上述语法限制搜索范围。

示例

h = findobj(objhandles,'-depth',d,___) 将搜索范围限制为 objhandles 中列出的对象及其后代,它们在图形对象层次结构中位于 d 级别以下。

示例

h = findobj(objhandles,'flat',___) 将搜索范围限制为仅 objhandles 中列出的对象。不搜索后代对象。使用 'flat' 选项等效于将 '-depth' 选项与 d = 0 结合使用。

示例

全部折叠

查找所有图形对象

打开实时脚本

删除所有现有图窗,然后创建一个随机值图。

close allplot(rand(5))

查找具有特定属性的图形对象 - MATLAB findobj (1)

返回图形根对象及其所有后代。

h = findobj
h = 8x1 graphics array: Root Figure (1) Axes Line Line Line Line Line

查找所有线条对象

打开实时脚本

删除所有现有图窗,然后创建一个多线图。

close allplot(magic(4))

查找具有特定属性的图形对象 - MATLAB findobj (2)

返回所有线条对象。

h = findobj('Type','line')
h = 4x1 Line array: Line Line Line Line

查找具有指定属性值的对象

打开实时脚本

用自定义颜色和线型绘制九个正弦波。

x = linspace(0,7);y = ones(length(x),9);for i = 1:9 y(:,i) = sin(x-i/5)';endplot(x,y)colororder({'red','green','blue'})ax = gca;ax.LineStyleOrder = {'-','--',':'};

查找具有特定属性的图形对象 - MATLAB findobj (3)

返回红色实线。然后,更改线条的粗细。

h = findobj('Color','red','LineStyle','-')
h = Line with properties: Color: [1 0 0] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [0 0.0707 0.1414 0.2121 0.2828 0.3535 0.4242 0.4949 0.5657 0.6364 0.7071 0.7778 0.8485 0.9192 0.9899 1.0606 1.1313 1.2020 1.2727 1.3434 1.4141 1.4848 1.5556 1.6263 1.6970 1.7677 1.8384 1.9091 1.9798 2.0505 2.1212 ... ] (1x100 double) YData: [-0.1987 -0.1289 -0.0586 0.0121 0.0827 0.1529 0.2224 0.2907 0.3576 0.4226 0.4856 0.5462 0.6040 0.6588 0.7103 0.7582 0.8024 0.8426 0.8785 0.9101 0.9371 0.9594 0.9769 0.9896 0.9973 1.0000 0.9977 0.9905 0.9782 0.9611 ... ] (1x100 double) Use GET to show all properties
h.LineWidth = 2;

查找具有特定属性的图形对象 - MATLAB findobj (4)

使用逻辑表达式查找对象

打开实时脚本

创建一个多线图。为每个图指定一个标识符。

x = linspace(-1,1);y1 = x;plot(x,y1,'Tag','linear')hold ony2 = x.^2;plot(x,y2,'Tag','quadratic')y3 = exp(x);plot(x,y3,'Tag','exponential')y4 = sin(x);plot(x,y4,'Tag','sinusoidal')hold off

查找具有特定属性的图形对象 - MATLAB findobj (5)

查找其 Tag 属性未设置为 'linear' 的所有对象。

h1 = findobj('-not','Tag','linear')
h1 = 6x1 graphics array: Root Figure (1) Axes Line (sinusoidal) Line (exponential) Line (quadratic)

查找其 Tag 属性未设置为 'linear''quadratic' 的所有对象。

h2 = findobj('-not',{'Tag','linear','-or','Tag','quadratic'})
h2 = 5x1 graphics array: Root Figure (1) Axes Line (sinusoidal) Line (exponential)

查找其 Tag 属性未设置为 'linear''quadratic' 的所有线条对象。

h3 = findobj('Type','line','-not',{'Tag','linear','-or','Tag','quadratic'})
h3 = 2x1 Line array: Line (sinusoidal) Line (exponential)

通过使用 '-and' 和花括号来提高前面语句的可读性。

h4 = findobj({'Type','line'},'-and',{'-not',{'Tag','linear','-or','Tag','quadratic'}})
h4 = 2x1 Line array: Line (sinusoidal) Line (exponential)

使用正则表达式查找对象

打开实时脚本

创建三个线图,并为其中两个图指定标识符。

x = linspace(-1,1);y1 = x;plot(x,y1)hold ony2 = x.^2;plot(x,y2,'Tag','Quadratic')y3 = exp(x);plot(x,y3,'Tag','Exponential')hold off

查找具有特定属性的图形对象 - MATLAB findobj (6)

查找具有非空 Tag 属性的所有对象。

h = findobj('-regexp','Tag','[^'']')
h = 2x1 Line array: Line (Exponential) Line (Quadratic)

查找具有指定属性的所有对象

打开实时脚本

创建一个包含四个值的向量。使用线图、区域图和条形图显示这些值。

y = [1 5 6 3];subplot(3,1,1)plot(y)subplot(3,1,2)area(y)subplot(3,1,3)bar(y)

查找具有特定属性的图形对象 - MATLAB findobj (7)

返回具有 BaseValue 属性的所有对象。

h = findobj('-property','BaseValue')
h = 2x1 graphics array: Bar Area

查找当前坐标区中的所有线条对象

打开实时脚本

创建一个随机值图,然后返回当前坐标区中的所有线条对象。

plot(rand(5))

查找具有特定属性的图形对象 - MATLAB findobj (8)

h = findobj(gca,'Type','line')
h = 5x1 Line array: Line Line Line Line Line

使用 h 查询第一个 Line 对象的 y 值。

values = h(1).YData
values = 1×5 0.6557 0.0357 0.8491 0.9340 0.6787

查找当前图窗中的所有对象

打开实时脚本

创建包含两个选项卡的图窗。通过为每个选项卡指定父容器,将坐标区添加到每个选项卡上。在第一个选项卡中绘制一条直线,在第二个选项卡中绘制一个曲面。

figuretab1 = uitab('Title','Tab1');ax1 = axes(tab1);plot(ax1,1:10)tab2 = uitab('Title','Tab2');ax2 = axes(tab2);surf(ax2,peaks)

查找具有特定属性的图形对象 - MATLAB findobj (9)

返回当前图窗中的所有对象及其后代。

h = findobj(gcf)
h = 8x1 graphics array: Figure (1) TabGroup Tab (Tab1) Tab (Tab2) Axes Axes Line Surface

限制搜索深度

打开实时脚本

创建带有两个堆叠子图的图窗。

subplot(2,1,1)x = linspace(0,10);y1 = sin(x);plot(x,y1)subplot(2,1,2)y2 = sin(5*x);plot(x,y2)

查找具有特定属性的图形对象 - MATLAB findobj (10)

查找当前图窗中的所有对象及其子级。

h1 = findobj(gcf,'-depth',1)
h1 = 3x1 graphics array: Figure (1) Axes Axes

查找当前图窗中的所有对象以及在图形对象层次结构中低两级的任何后代。

h2 = findobj(gcf,'-depth',2)
h2 = 5x1 graphics array: Figure (1) Axes Axes Line Line

使用 'flat' 选项将搜索范围限制为当前图窗和当前坐标区。

h3 = findobj([gcf,gca],'flat')
h3 = 2x1 graphics array: Figure (1) Axes

输入参数

全部折叠

prop属性名称
字符向量 | 字符串标量

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

示例: 'Tag'

示例: 'Type'

value属性值
标量 | 数组

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

oper逻辑运算符
'-and' (默认) | '-or' | '-xor'

逻辑运算符,指定为 '-and''-or''-xor'。逻辑运算符优先级遵循 MATLAB® 优先级规则。有关详细信息,请参阅运算符优先级

要控制运算符优先级,请对元胞数组中的 prop,value 对组进行组合。例如,查找 Tag 属性设置为 'button one'Color 属性设置为除了 'red''blue' 以外的值的所有对象:

h = findobj('Tag','button one','-and', ... '-not',{'Color','red','-or','Color','blue'})

expr正则表达式
字符串数组 | 字符向量 | 字符向量元胞数组

正则表达式,指定为字符串数组、字符向量或字符向量元胞数组。expr 可以包含字符、元字符、运算符、标记和标志,它们指定属性值中要匹配的模式。仅当属性值是字符串或字符向量时,才能使用 expr。有关正则表达式的详细信息,请参阅 regexp

objhandles要从中搜索的对象
图形对象数组

要从中进行搜索的对象,指定为图形对象数组。除非指定 '-depth''flat' 选项,否则 findobj 将搜索图形对象层次结构中输入数组 objhandles 中的对象及其所有后代。

d搜索深度
非负整数

搜索深度,指定为一个指示输入数组 objhandles 中任何给定对象下面的级别数的非负整数。

  • d = n - 搜索 objhandles 中每个对象下面的 n 级层次结构。

  • d = 0 - 仅搜索与 objhandles 中对象相同的级别。这等效于指定 'flat' 选项。

  • d = inf - 搜索 objhandles 中对象下方的所有级别。这等效于不指定 '-depth''flat' 选项的默认搜索。

提示

  • 如果对象的 HandleVisibility 属性设置为 'off',则 findobj 不会返回该图形对象或其任何后代。要返回层次结构中的所有对象,包括隐藏的对象,请使用 findall 函数。

  • findobj 与任何合法的属性值正确匹配。例如,以下代码查找 Color 属性设置为 redr[1 0 0] 的所有对象:

    findobj('Color','r')
  • 如果某个图形对象是 objhandles 中标识的多个对象的后代,则每次 findobj 遇到其句柄时,MATLAB 都会搜索该对象。因此,隐式引用某个图形对象可能会导致多次返回该对象。

版本历史记录

在 R2006a 之前推出

另请参阅

copyobj | findall | findobj | gcf | gca | gcbo | gco | get | regexp | set | groot

主题

  • 查找对象
  • 图形对象层次结构

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

查找具有特定属性的图形对象 - MATLAB findobj (11)

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:

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
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

查找具有特定属性的图形对象 - MATLAB findobj (2024)
Top Articles
Congdon Heart And Vascular Center
Bones And All Showtimes Near Amc Boston Common 19
WALB Locker Room Report Week 5 2024
Walgreens Harry Edgemoor
Truist Bank Near Here
Txtvrfy Sheridan Wy
CKS is only available in the UK | NICE
Co Parts Mn
Noaa Swell Forecast
Walgreens Alma School And Dynamite
Tlc Africa Deaths 2021
Sunday World Northern Ireland
Midway Antique Mall Consignor Access
World Cup Soccer Wiki
Phillies Espn Schedule
Oriellys St James Mn
Miss America Voy Forum
Vcuapi
Apus.edu Login
Nine Perfect Strangers (Miniserie, 2021)
Traveling Merchants Tack Diablo 4
Loft Stores Near Me
Cvs El Salido
Morristown Daily Record Obituary
Johnnie Walker Double Black Costco
Www.craigslist.com Savannah Ga
Conscious Cloud Dispensary Photos
1145 Barnett Drive
Dashboard Unt
Black Lion Backpack And Glider Voucher
Roseann Marie Messina · 15800 Detroit Ave, Suite D, Lakewood, OH 44107-3748 · Lay Midwife
Restored Republic
Proto Ultima Exoplating
Purdue Timeforge
How Much Is An Alignment At Costco
Myhrconnect Kp
Scioto Post News
Exploring The Whimsical World Of JellybeansBrains Only
Ket2 Schedule
Puffco Peak 3 Red Flashes
Regis Sectional Havertys
Mcgiftcardmall.con
Promo Code Blackout Bingo 2023
Spurs Basketball Reference
Phmc.myloancare.com
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Mail2World Sign Up
El Patron Menu Bardstown Ky
25100 N 104Th Way
Sleep Outfitters Springhurst
Arnold Swansinger Family
login.microsoftonline.com Reviews | scam or legit check
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 6257

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.