Find graphics objects with specific properties (2024)

Find graphics objects with specific properties

collapse all in page

Syntax

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',___)

Description

example

h = findobj returns the graphics root object and all of its descendants.

example

h = findobj(prop,value) returns all objects in the hierarchy that have their property prop set to value.

example

h = findobj('-not',prop,value) returns all objects whose specified property is not set to the specified value.

example

h = findobj(prop1,value1,oper,prop2,value2) applies the logical operator oper to the prop,value pairs. For example, h = findobj('LineStyle','--','-and','Marker','o') returns all objects that have a dashed line style and circular markers.

example

h = findobj('-regexp',prop,expr) uses a regular expression to find objects with specific property values. Objects with property values satisfying the regular expression are returned.

example

h = findobj('-property',prop) returns all objects that have the specified property.

example

h = findobj(prop1,value1,...,propN,valueN) returns all objects in the hierarchy that have the specified properties set to the specified values. You can replace prop,value pairs with other input argument combinations from the previous syntaxes. For example, h = findobj(prop1,value1,'-not',prop2,value2,'-property',prop3) returns all objects that satisfy these three conditions:

  • The object has a property prop1 set to value1.

  • The object has a property prop2 whose value is not set to value2.

  • The object has a property prop3.

example

h = findobj(objhandles,___) restricts the search to the objects listed in objhandles and all of their descendants. You can restrict the search for any of the previous syntaxes.

example

h = findobj(objhandles,'-depth',d,___) restricts the search to the objects listed in objhandles and their descendants that are up to d levels lower in the graphics object hierarchy.

example

h = findobj(objhandles,'flat',___) restricts the search to the objects listed only in objhandles. The descendant objects are not searched. Using the 'flat' option is the same as using the '-depth' option with d = 0.

Examples

collapse all

Find All Graphics Objects

Open Live Script

Delete all existing figures, and then create a plot of random values.

close allplot(rand(5))

Find graphics objects with specific properties (1)

Return the graphics root object and all of its descendants.

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

Find All Line Objects

Open Live Script

Delete all existing figures, and then create a multiline plot.

close allplot(magic(4))

Find graphics objects with specific properties (2)

Return all line objects.

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

Find Objects with Specified Property Values

Open Live Script

Plot nine sine waves with custom colors and line styles.

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 = {'-','--',':'};

Find graphics objects with specific properties (3)

Return the solid red line. Then, change the thickness of the line.

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;

Find graphics objects with specific properties (4)

Find Objects Using Logical Expressions

Open Live Script

Create a multiline plot. Specify an identifier for each plot.

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

Find graphics objects with specific properties (5)

Find all objects whose Tag property is not set to 'linear'.

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

Find all objects whose Tag property is not set to 'linear' or 'quadratic'.

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

Find all line objects whose Tag property is not set to 'linear' or 'quadratic'.

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

Improve the readability of the previous statement by using '-and' and curly brackets.

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

Find Objects Using Regular Expression

Open Live Script

Create three line plots and assign an identifier to two of the plots.

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

Find graphics objects with specific properties (6)

Find all objects that have a nonempty Tag property.

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

Find All Objects with Specified Property

Open Live Script

Create a vector of four values. Display the values using a line plot, an area plot, and a bar graph.

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

Find graphics objects with specific properties (7)

Return all objects that have a BaseValue property.

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

Find All Line Objects in Current Axes

Open Live Script

Create a plot of random values, and then return all line objects in the current axes.

plot(rand(5))

Find graphics objects with specific properties (8)

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

Use h to query the y values of the first Line object.

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

Find All Objects in Current Figure

Open Live Script

Create a figure with two tabs. Add axes to each tab by specifying the parent container for each one. Plot a line in the first tab and a surface in the second tab.

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

Find graphics objects with specific properties (9)

Return all objects in the current figure and its descendants.

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

Restrict Search Depth

Open Live Script

Create a figure with two stacked subplots.

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)

Find graphics objects with specific properties (10)

Find all objects in the current figure and its children.

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

Find all objects in the current figure and any descendants that are up to two levels lower in the graphics object hierarchy.

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

Restrict the search to the current figure and the current axes using the 'flat' option.

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

Input Arguments

collapse all

propProperty name
character vector | string scalar

Property name, specified as a character vector or string scalar. For more information, see Graphics Object Properties.

Example: 'Tag'

Example: 'Type'

valueProperty value
scalar | array

Property value, specified as a scalar or array.

operLogical operator
'-and' (default) | '-or' | '-xor'

Logical operator, specified as '-and', '-or', or '-xor'. Logical operator precedence follows MATLAB® precedence rules. For more information, see Operator Precedence.

To control operator precedence, group prop,value pairs within cell arrays. For example, find all objects that have a Tag property set to 'button one' and a Color property set to a value other than 'red' or 'blue':

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

exprRegular expression
string array | character vector | cell array of character vectors

Regular expression, specified as a string array, character vector, or cell array of character vectors. expr can contain characters, metacharacters, operators, tokens, and flags that specify patterns to match in the property value. You can use expr only when the property value is a string or character vector. For more information about regular expressions, see regexp.

objhandlesObjects to search from
array of graphics objects

Objects to search from, specified as an array of graphics objects. Unless you specify the '-depth' or 'flat' options, findobj searches the objects in the input array objhandles and all of their descendants in the graphics object hierarchy.

dDepth of search
nonnegative integer

Depth of search, specified as a nonnegative integer indicating the number of levels below any given object in the input array objhandles.

  • d = n — Search n levels of the hierarchy below each object in objhandles.

  • d = 0 — Search only the same level as the objects in objhandles. This is equivalent to specifying the 'flat' option.

  • d = inf — Search all levels below the objects in objhandles. This is equivalent to a default search without specifying the '-depth' or 'flat' options.

Tips

  • If the HandleVisibility property of an object is set to 'off', findobj does not return that graphics object or any of its descendants. To return all objects in the hierarchy, including hidden objects, use the findall function.

  • findobj correctly matches any legal property value. For example, this code finds all objects having a Color property set to red, r, or [1 0 0]:

    findobj('Color','r')
  • When a graphics object is a descendant of more than one object identified in objhandles, MATLAB searches the object each time findobj encounters its handle. Therefore, implicit references to a graphics object can result in multiple returns of the object.

Version History

Introduced before R2006a

See Also

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

Topics

  • Find Objects
  • Graphics Object Hierarchy

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.

Find graphics objects with specific properties (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

Find graphics objects with specific properties (2024)

FAQs

How do you find all objects in MATLAB? ›

h = findall( objhandles , prop 1, value 1,..., prop N, value N) returns the handles of all objects in the hierarchy that have the specified properties set to the specified values. For example, h = findall(gcf,'Type','text','Color','r') returns all text objects in the current figure that have a red color.

How to use findobj in MATLAB? ›

To use findobj , pick a property value that uniquely identifies the object. This example uses the text String property: hText = findobj('String','\leftarrowsin(t) = . 707');

How to get figure properties in MATLAB? ›

Using the get() function we can examine the properties on the figure. In MATLAB this will return an object, but in Octave, this will return a struct.

What is a graphic object? ›

Graphics objects are the components used by MATLAB® to create visualizations of data. Each object plays a specific role in the graphics display. For example, a line plot consists of a figure object, an axes object, and a chart line object. You can customize graphics objects by setting their properties.

How do you find the property of an object in MATLAB? ›

The findprop method returns the matlab. metadata. Property object for the specified object and property. The property can also be a dynamic property created by the addprop method of the dynamicprops class.

How do you find the objects of a class in MATLAB? ›

Hmatch = findobj( H ,'-class', class ) finds all objects belonging to the specified class. Hmatch = findobj( H ,'-isa', class ) finds all objects belonging to the specified class.

How to use Chebfun in MATLAB? ›

To use Chebfun in matlab, you will need to add the `chebfun` directory to the matlab path as above. Most Chebfun commands are overloads of familiar matlab commands — for example sum(f) computes an integral, roots(f) finds zeros, and u = L\f solves a differential equation.

How to use mux in MATLAB? ›

Additionally, this example uses the Mux (Simulink) block to combine the CAN messages to be transmitted into a single vector. If your CAN Pack blocks are configured to output as a bus, then use the Vector Concatenate (Simulink) block to combine the CAN messages instead.

What does Caxis do in MATLAB? ›

caxis auto lets MATLAB compute the color limits automatically using the minimum and maximum data values.

What are properties in MATLAB? ›

Properties contain object data. Classes define the same properties for all objects, but each object can have unique data values. Property attributes control what functions or methods can access the property. You can define functions that execute whenever you set or query property values.

How do you check if an object property exists in MATLAB? ›

You can verify the existence of a property of an object before attempting to set it by using isprop in an if -statement. Create a line plot and assign a variable to the object. Use an if -statement to verify that object p has the LineStyle property.

How to change the properties of various objects in MATLAB gui? ›

In plot edit mode, double-clicking a mapped object activates the MATLAB Property Editor for that object. From the Property Editor you can launch the Property Inspector, a GUI that lists the properties and values of the selected object and allows you to modify them.

What are 5 examples of graphics? ›

Images that are generated by a computer are called computer graphics. Examples are photographs, drawings, line art, mathematical graphs, line graphs, charts, diagrams, typography, numbers, symbols, geometric designs, maps, engineering drawings, or other images. Graphics often combine text, illustration, and color.

What are the types of graphics objects in MATLAB? ›

When MATLAB creates a plot, it creates a series of graphics objects. Figures, axes, lines, patches, and text are examples of graphics objects. The figure below has three graphics objects -- an axes, a line, and a text object.

How do you create a graphic object? ›

B. 1 Creating graphics
  1. Create a JFrame object, which is the window that will contain the canvas.
  2. Create a Drawing object (which is the canvas), set its width and height, and add it to the frame.
  3. Pack the frame (resize it) to fit the canvas, and display it on the screen.

How do I search an entire project in MATLAB? ›

Project-Wide Search

If you want to search referenced project files, open the referenced project. On the Project tab, click the down arrow to expand the Tools gallery. Under Project Files, click Search. Alternatively, type in the file filter box, and the project provides a link to try searching inside files instead.

What does the function all () do in MATLAB? ›

The all function reduces such a vector of logical values to a single condition. In this case, B = all(A < 0.5) yields logical 0 . This makes all particularly useful in if statements.

How do I see all variables in MATLAB? ›

To view the variables in the workspace, use the Workspace browser. To view the contents of MAT-files, use the Details Panel of the Current Folder browser. In MATLAB Online™, to view the contents of MAT-files, preview them by clicking the Preview button to the right of the MAT-file in the Files browser.

Top Articles
Quick + Easy Biscuit Recipes and Meal Ideas
23 Brilliant Barefoot Contessa Recipes To Try At Home
Varsity Competition Results 2022
R/Sellingsunset
Britley Ritz - K99.1FM
Carmax Chevrolet Tahoe
The Canterville Ghost Showtimes Near Northwoods Cinema 10
Dryers At Abc Warehouse
Bank Of America Operating Hours Today
Un-Pc Purchase Crossword Clue
New & Used Motorcycles for Sale | NL Classifieds
Ella And David Steve Strange
T33N Leaks 5 17
Gas Buddy Prices Near Me Zip Code
Kodiak C4500 For Sale On Craigslist
Contenidos del nivel A2
Dr. Nicole Arcy Dvm Married To Husband
Car Star Apple Valley
27 Sage Street Holmdel Nj
8005607994
Jockey Standings Saratoga 2023
Square Coffee Table Walmart
Horseheads Schooltool
R Mariokarttour
Pokerev Telegram
359 Greenville Ave Staunton Va
3 Izzy Ln, Kittery, ME 03904 - MLS 1603480 - Coldwell Banker
Adriana Zambrano | Goosehead Insurance Agent in Metairie, Louisiana
Sam's Club Stafford Gas Price
Star Wars Galaxy Of Heroes Forums
Switchback Travel | Best Camping Chairs of 2024
Surprise | Visit Arizona
The dangers of statism | Deirdre McCloskey
Active Dispatch Calls Escambia County
Charlotte North Carolina Craigslist Pets
Avalon Hope Joi
Weather Radar Jamestown
Erie Pa Craigslist
Dom Tradingview
Ati Recommended Cut Scores 2023
How To Delete Jackd Account
Build:Mechanist - Power Mechanist
United States Map Quiz
2022 Basketball 247
5 Pros & Cons of Massage Envy (VS Independent Massage Therapists)
Swim University Chemical Calculator
Best Asian Bb Cream For Oily Skin
Apartments for Rent in Buellton, CA - Home Rentals | realtor.com®
Liberty 1098-T
Wv Anon Vault
Jetblue Flight Status & Tracker
Latest Posts
Article information

Author: Dan Stracke

Last Updated:

Views: 6045

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Dan Stracke

Birthday: 1992-08-25

Address: 2253 Brown Springs, East Alla, OH 38634-0309

Phone: +398735162064

Job: Investor Government Associate

Hobby: Shopping, LARPing, Scrapbooking, Surfing, Slacklining, Dance, Glassblowing

Introduction: My name is Dan Stracke, I am a homely, gleaming, glamorous, inquisitive, homely, gorgeous, light person who loves writing and wants to share my knowledge and understanding with you.