フィルターのクリア

Save figure in a subplot loop

7 ビュー (過去 30 日間)
Frederik Reese
Frederik Reese 2022 年 5 月 4 日
編集済み: Jonas 2022 年 5 月 4 日
Hi,
i have this code an want to save the figure as png and fig , if there are 5 subplots.
The name should be then for example: hours_5, hours_10....
for i=1:100
if rem(i-1, 5) == 0
figure;
end
sgtitle('WSPL zeitlicher Verlauf Modell D Teil 2')
a(i)=subplot(5, 1, rem(i-1, 5)+1)
hold on;
[maxHQextrem,indexHQextrem]=max(Hoehe_HQextrem(:,i)- Hoehe_Z(:,i));
[maxHQ5000,indexHQ5000]=max(Hoehe_HQ5000(:,i)- Hoehe_Z(:,i));
[maxHQ10000,indexHQ10000]=max(Hoehe_HQ10000(:,i)- Hoehe_Z(:,i));
str = ['Maximaler Überlauf [m]: HQextrem ',num2str(maxHQextrem),' HQ5000 ',num2str(maxHQ5000),' HQ10000 ',num2str(maxHQ10000)];
b(i) = annotation('textbox','String',str,'Position',a(i).Position,'Vert','bottom','FitBoxToText','on');
hold on
% annotation('textbox', 'String',str)
p1=plot (Distanz_Z(:,i) , [Hoehe_Z(:,i), Hoehe_HQextrem(:,i), Hoehe_HQ5000(:,i), Hoehe_HQ10000(:,i)]);
title(['Zeit [h] ', num2str(i)])
grid on
xline(indexHQextrem,'-','Maximum','LabelOrientation','horizontal')
xline(indexHQ5000)
xline(indexHQ10000)
leg=legend(p1,{'Geländehöhe','HQextrem','HQ5000', 'HQ10000'})
title(leg,'WSPL')
newcolors = {'#000000','#7E2F8E','#0000FF','#00FFFF'};
colororder(newcolors)
xlabel('FKM [km]');
ylabel('Höhe über NN [m]')
xticks([738.98 1734.44 2744.03 3687.56 4722.17 5762.52 6831.7 7228.84])
xticklabels({'118','117','116','115', '114', '113', '112', '111'})
end
thanks in advance

採用された回答

Voss
Voss 2022 年 5 月 4 日
for i=1:100
if rem(i-1, 5) == 0
f = figure;
end
sgtitle('WSPL zeitlicher Verlauf Modell D Teil 2');
a(i)=subplot(5, 1, rem(i-1, 5)+1);
% ...
% ... your plotting code
% ...
if rem(i-1, 5) == 4
saveas(f,sprintf('hours_%d.png',i));
saveas(f,sprintf('hours_%d.fig',i));
end
end
  4 件のコメント
Jonas
Jonas 2022 年 5 月 4 日
編集済み: Jonas 2022 年 5 月 4 日
use the print function or exportgraphics to control the resolution of the image
Voss
Voss 2022 年 5 月 4 日
To maximize, you can use the 'WindowState' property of the figure if your version of MATLAB supports it. Otherwise, there are functions on the File Exchange you can use.

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by