필터 지우기
필터 지우기

How can I use the command 'tiledlayout' inside a loop

조회 수: 21 (최근 30일)
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA 2022년 5월 12일
댓글: the cyclist 2022년 5월 15일
How I can I use 'tiledlayout' if I need to plot two graphs with each one has multiple graphs? I was using subplot but the white space area is too much. Is there any other command for this? I also need to generate PDF finally.

채택된 답변

the cyclist
the cyclist 2022년 5월 12일
The key is to create two different figures, each of which you can build up a tiled layout.
Here is a trivial example of two figures, each of which has three tiles:
rng default
numberFigures = 2;
fig_handles = zeros(numberFigures,1);
for nf = 1:numberFigures
fig_handles(nf) = figure;
tiledlayout(3,1);
nexttile
plot(rand(5))
nexttile
plot(rand(7))
nexttile
plot(rand(11))
end
  댓글 수: 2
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA 2022년 5월 15일
Thank you for the help. But in my case, I have to create a PDF. There are two figures in the PDF. Each figure has 4 results of simulation plotted by using for loop and hold on. How can I solve the problem?
the cyclist
the cyclist 2022년 5월 15일
You can use the exportgraphics command to write multiple figures to a single PDF.
Here is an example, based on my other code, that writes two figures to PDF, where each figure is a tiled layout of four plots.
rng default
numberFigures = 2;
numberTiles = 4;
fig_handles = zeros(numberFigures,1);
for nf = 1:numberFigures
fig_handles(nf) = figure;
t = tiledlayout(numberTiles,1);
for nt = 1:numberTiles
nexttile
plot(rand(5)) % This is just an example. Use your simulation to make the plot.
end
exportgraphics(t,'myplots.pdf','Append',true)
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by