How to select active tile in tiledlayout
192 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Francesco Burgalassi
il 17 Dic 2020
Commentato: Sven Merk
il 6 Nov 2023
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 Commenti
Risposta accettata
KALYAN ACHARJYA
il 17 Dic 2020
Modificato: KALYAN ACHARJYA
il 17 Dic 2020
"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 Commenti
Dave B
il 22 Dic 2020
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))
Più risposte (1)
Sven Merk
il 3 Nov 2023
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 Commenti
Dave B
il 3 Nov 2023
@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
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!