Saving figures in a loop with variable file names

27 ビュー (過去 30 日間)
Saar Peles
Saar Peles 2020 年 4 月 29 日
Hi I'm trying to run a loop that creates plots and then saves them in a specific file. I'm having trouble saving the figures with the correct names and also populating them in a specific file. I realize what I have currently in the filename is invalid but here is what I have so far:
order = ["rr_la", "ll", "rr_sa", "cc"];
orderS = ["epi", "mid", "endo", "ave"];
for j = 1:16 % through AHA regions but not the apex
region2 = "AHA" + j;
for k = 1:4 % through order of strains
epi = S10.(region2).stat.(order(k)).epi.org;
mid = S10.(region2).stat.(order(k)).mid.org;
endo = S10.(region2).stat.(order(k)).endo.org;
ave = S10.(region2).stat.(order(k)).ave.org;
phase = 1:size(epi,1);
plot(phase,epi,phase,mid,phase,endo,phase,ave);
legend('epi','mid','endo','ave');
grid
filename = [(Snum) '_AHAPlot' (region2) (order(k)) '.fig'];
saveas(gcf,filename);
end
end
  1 件のコメント
Shahnil Sadiq Noorani
Shahnil Sadiq Noorani 2020 年 4 月 30 日
hi
can you please help me in this question

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

採用された回答

Image Analyst
Image Analyst 2020 年 4 月 29 日
Assuming they're all strings, try sprintf():
filename = sprintf('%s_AHAPlot%s%s.png', Snum, region2, order(k));
  2 件のコメント
Saar Peles
Saar Peles 2020 年 4 月 29 日
Seemed to work in creating the files, how do I make them populate a specific file?
Image Analyst
Image Analyst 2020 年 4 月 30 日
I don't know what that means. The line of code I gave constructs a filename string. You then need other lines of code to create the file, such as
currentFigure = gcf;
exportgraphics(currentFigure, filename); % r2020a release or later only

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

その他の回答 (0 件)

カテゴリ

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