필터 지우기
필터 지우기

How to select active tile in tiledlayout

조회 수: 231 (최근 30일)
Francesco Burgalassi
Francesco Burgalassi 2020년 12월 17일
댓글: Sven Merk 2023년 11월 6일
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
Francesco Burgalassi 2020년 12월 17일
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