Nesting tiledlayouts within another tiledlayout

145 views (last 30 days)
Matt J
Matt J on 31 Mar 2021
Commented: Matt J on 2 Apr 2021
I would like to created a tiledlayout and, within each of the tiles, start another tiledlayout. I assume this kind of nesting is possible since, in the documentation for TiledChartLayout objects, it says that the parent of a TiledChartLayout can be another TiledChartLayout. However, the following example fails to produce the desired nesting. Instead of nesting the second sub-layout in the second tile, it tries to put it in the first tile. Is it possible to do what I am trying to do? If not, under what circumstances does it make sense to parent a TiledChartLayout to another TiledChartLayout.
m1=[5,6];
m2=[1,1,1,2];
T=tiledlayout(3,1); %Outer layout
nexttile(T,[1,1]); axis off %Next outer tile
t=tiledlayout(T,1,2); %first inner layout
for i=1:2
nexttile(t);
plot(rand(5,m1(i)));
legend('Location','southoutside')
end
nexttile(T,[2,1]); axis off %Next outer tile
t=tiledlayout(T,2,2); %second inner layout
for i=1:4
nexttile(t);
plot(rand(5,m2(i)));
legend('Location','southoutside')
end

Accepted Answer

Yemi  Ajayi
Yemi Ajayi on 1 Apr 2021
Edited: Yemi Ajayi on 1 Apr 2021
Adapting your example:
T=tiledlayout(3,1); %Outer layout
for i=1:3
t=tiledlayout(T,1,1); % Inner layout
t.Layout.Tile = i;
t.Layout.TileSpan = [1 1];
nexttile(t);
plot(rand(5,(i)));
end
lgd = legend('Orientation',"horizontal");
lgd.Layout.Tile = 'south';
Hope that helps.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!