How do use 'flow' in a tiled plot while forcing a maximum of 2 columns?

9 vues (au cours des 30 derniers jours)
Rafael Cordero
Rafael Cordero le 23 Mar 2023
Modifié(e) : Adam Danz le 23 Mar 2023
Hello folks,
I want to produce a series of tiled plots. Problem is, I do not know a priori the number of tiles. In this sense, 'flow' is very helpful. However, I want the tiles constrained to two columns, so that the tiles could possibly exist dynamically as [2 x1], [2 x 2], [2 x 3], [2 x 4] etc.
Is it possible to do this?
Thank you!
PS: I have R2022b so cant use 'Vertical'

Réponses (1)

Adam Danz
Adam Danz le 23 Mar 2023
Modifié(e) : Adam Danz le 23 Mar 2023
A flow arrangement with a fixed number of columns (or rows) greater than 1 is not currently available. A new feature in MATLAB R2023a is the Vertical and Horizontal flow arrangements that allow for 1xn or nx1 flexible flow.
If you're using R2023a or later, you could arrange two tiledlayout objects that each have a nx1 vertical arrangement.
Here's a demo:
% Set up figure
figure()
tclmain = tiledlayout(1,2);
tclLeft = tiledlayout(tclmain,'vertical');
tclLeft.Layout.Tile = 1;
tclRight = tiledlayout(tclmain,'vertical');
tclRight.Layout.Tile = 2;
% create a random number of plots
nPlots = randi(5)+4;
for n = 1:nPlots
% Select right column if n is odd
% otherwise select left column
if mod(n,2)==0
tcl = tclRight;
else
tcl = tclLeft;
end
ax = nexttile(tcl);
plot(ax,fft(eye(randi(10)+1)))
end
drawnow
% Make sure the right column has an equal number of tiles
% as the left column.
if tclRight.GridSize(1) < tclLeft.GridSize(1)
nexttile(tclRight)
end

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by