How to select active tile in tiledlayout
198 ビュー (過去 30 日間)
古いコメントを表示
Francesco Burgalassi
2020 年 12 月 17 日
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?
0 件のコメント
採用された回答
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 件のコメント
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
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
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
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!