findobj
Finds visible graphics objects by property values.
Category: Graphics > Graphics Objects
Syntax
h = findobj
Returns the root and all visible objects.
h = findobj(Name, Value)
Returns objects anywhere whose property matches.
h = findobj(parent, Name, Value)
Searches parent and its descendants only.
h = findobj(parent, '-depth', d, ___)
Limits how many levels below parent are searched.
Description
A common use is picking one line out of a plot by Tag or DisplayName to change it afterwards. Objects with HandleVisibility set to 'off' are skipped; use findall to include them.
Input arguments
parent- Figure, axes or other object to search under.
Name, Value- Property and the value to match; several pairs are combined with AND (use
'-or'for OR).
Output arguments
h- Column array of handles; empty if nothing matches.
Example
Pick a line by tag
f = figure;
ax = axes;
l1 = plot(1:3, 'Tag', 'one');
hold on
l2 = plot(3:-1:1, 'Tag', 'two');
o = findobj(ax, 'Tag', 'two');
disp(o == l2)
disp(numel(findobj(f, 'Type', 'line')))
Output
1
2