Loop for mutliple (but variable) number of plots on multiple pages

16 ビュー (過去 30 日間)
newbie9
newbie9 2019 年 8 月 17 日
コメント済み: newbie9 2019 年 8 月 19 日
I'm trying to make multiple pages of subplots, but the number of pages varies. There will be 12 subplots per page. Note that sometimes there will be 13 plots, sometimes 24, whatever--it varies. the xy data is just dummy data to set up the template.
Below is my starter script, but I am not sure of the best way to automate it so it "kicks over" to a new page on the 13th plot?
x = randn(5,1);
y = randn(5,1);
nplots = 13;
for ii = 1:nplots
if ii < 12
subplot(4,3,ii)
plot(x,y)
title(strcat('plot #', num2str(ii)), 'FontSize', 6)
box on
end
end
h = gcf;
set(h, 'PaperPositionMode', 'auto');
set(h, 'PaperOrientation', 'landscape');
set(h, 'PaperUnits', 'inches', 'PaperPosition', [0,0,11,8.5])
%figOut = 'test_page1';
%print(figOut, '-r300', '-dpdf')
%close all;
untitled.jpg

採用された回答

dpb
dpb 2019 年 8 月 17 日
Figure out how many figures you need a priori...
nplots = 13;
pperfigure=12;
nfigures=ceil(nplots/pperfigure);
nUp=pperfigure;
n=0;
for f=1:nfigures
hF(f)=figure;
if f==nfigures, nUp=mod(nplots,pperfigure); end
for ii = 1:nUp
hAx(f,ii)=subplot(4,3,ii);
...
end
end
  3 件のコメント
dpb
dpb 2019 年 8 月 19 日
編集済み: dpb 2019 年 8 月 19 日
You're welcome...you did catch that n was to be a counter on which dataset is being plotted that I didn't increment above, I presume, and did have a way to select the correct x,y data for the nth plot.
newbie9
newbie9 2019 年 8 月 19 日
Yes, that was actaully clear and I renamed it 'counter' in my final script

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by