How to select active tile in tiledlayout
    조회 수: 120 (최근 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?
댓글 수: 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
참고 항목
카테고리
				Help Center 및 File Exchange에서 Axes Appearance에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

