How to select active tile in tiledlayout

198 次查看(过去 30 天)
I want to create one figure with 16 plots arranged in a 2x8 shape. I use
tiledlayout(2,8)
to create the layout and then use the
nexttile
command followed by
plot(x,y)
to insert the plot in the next available tile. I repeat this process 16 times and i get my figure.
If now, for example, i want to go to the tile in the 2x3 postion and add a new plot while hold is activated, how do I do that? With the subplot command, i would have typed
subplot(2,8,11)
to go there and work on that plot. How can I do the same thing but with the tiledlayout command?

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020-12-17
编辑:KALYAN ACHARJYA 2020-12-17
"If now, for example, i want to go to the tile in the 2x3 postion and add a new plot while hold is activated, how do I do that? With the subplot command, i would have typed"
One way: e.g
data=1:100;
tiledlayout(2,2);
fig1=subplot(2,2,1),plot(data,log(data));
subplot(2,2,4),plot(data,log(data)+2);
% Let's go to the previous tile 2,1,1
axes(fig1)
hold on;
plot(data,log(data)+2);
  2 个评论
Francesco Burgalassi
This solves my problem. Thank you.
However, if I use the subplot command instead of nexttile, the 'Padding' value in the tiledlayout command loses its effect (the figure has again a lot of free space around the plots, as if i was using subplot instead of tiledlayout from the beginning). How can i avoid it?
Dave B
Dave B 2020-12-22
This isn't a great approach - subplot and nexttile are totally separate layout tools. When you call subplot you're moving back to using subplot and the TiledChartLayout is gone.
Getting the axes from tiledlayout is very similar however, you just use the nexttile command:
tiledlayout(2,2)
for i = 1:4
nexttile
plot(rand(10,1))
end
% Add something to the third plot
nexttile(3);
hold on
plot(rand(10,1))

请先登录,再进行评论。

更多回答(1 个)

Sven Merk
Sven Merk 2023-11-3
This code updates tile 2x3 with a second plot, using only tiledlayout.
rows = 2;
columns = 8;
tiledlayout(rows, columns);
for i = 1:rows*columns
nexttile;
plot(1:2);
end
tile_of_interest = [2, 3];
tile_number = (tile_of_interest(1) - 1) * columns + tile_of_interest(2);
nexttile(tile_number);
hold on
plot(1:2, 2:-1:1, "r");
hold off
  2 个评论
Dave B
Dave B 2023-11-3
@Sven Merk - starting in R2022b you can use tilenum to retrieve the tile number. The math isn't difficult, but it's one less thing to have to write, and tilenum will check the layout's number of rows/columns as well as the TileIndexing:
rows = 2;
columns = 8;
t = tiledlayout(rows, columns);
for i = 1:rows*columns
nexttile
plot(1:2);
end
row = 2;
column = 3;
tile_number = tilenum(t, row, column);
nexttile(tile_number);
hold on
plot(1:2, 2:-1:1, "r");
hold off
Sven Merk
Sven Merk 2023-11-6
Good to know, thank you. I didn't see this.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by