%% Restrict Search Depth
% 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 all objects in the current figure and its children.

h1 = findobj(gcf,'-depth',1)

% 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)

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

h3 = findobj([gcf,gca],'flat')

% Copyright 2020 The MathWorks, Inc.