How to save multiple figures with subplots as a single .fig file in an for loop

27 ビュー (過去 30 日間)
In-chan Kim
In-chan Kim 2020 年 3 月 2 日
コメント済み: Ruger28 2020 年 3 月 4 日
Hi
I want to save as .fig file multiple figures, each of which have subplots in them, created within a for loop.
I'd like to save each .fig file for each iteration of the loop.
At the moment, I have these plots, which I try to put into one output called figs. And I have a figs being created in each iteration.
I then try to save it.
But it's not working.
Also, I get a lot of figures for each for loop, so it'd be great if I could not actually bring up a figure each time, but still save it, and be able to make them into figures after I open up the saved file
Thanks!
within the for loop
figs(1,1)=figure;
subplot(2,2,1)
cdfplot(baseavgpricecomp)
subplot(2,2,2)
etc.
figs(1,2)=figure;
subplot(2,2,1)
etc.
% for each iteration
figname = sprintf('Form1_Scenario%dfigs',j);
figpath='Analysis';
saveas(figs, fullfile(figpath, figname), 'fig')

回答 (1 件)

Ruger28
Ruger28 2020 年 3 月 2 日
編集済み: Ruger28 2020 年 3 月 2 日
Try this. Pay special attention to the last line.
% within the for loop
figs(1,1)=figure;
subplot(2,2,1)
cdfplot(baseavgpricecomp)
subplot(2,2,2)
% etc.
figs(1,2)=figure;
subplot(2,2,1)
% etc.
% for each iteration
figname = sprintf('Form1_Scenario%dfigs',j);
figpath='Analysis';
saveas(figs, fullfile(figpath, [figname,'.fig'])); % changed how name is saved
  4 件のコメント
In-chan Kim
In-chan Kim 2020 年 3 月 3 日
Afraid not. Still getting an error. Maybe it's to do with the format of figs? Please see the picture below
Ruger28
Ruger28 2020 年 3 月 4 日
Probably easier to save each individual figure as its own .fig file.

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

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by