フィルターのクリア

saving multiple figures to a named path

3 ビュー (過去 30 日間)
Stelina
Stelina 2014 年 4 月 26 日
編集済み: dpb 2021 年 8 月 29 日
Dear community,
I have a script that produces multiple figures and I would like to save them automatically to a named folder. I have looked to similar examples at this forum but I still cannot figure out how to create multiple handles. The result is that, although the figures are plotted and seem to be saved in the format I have specified (.bmp), only the lastly created figure is saved in the specified folder.
######################################################################
The code I am using is the following: (this part of the code rests inside a for loop, with n being the counter)
figure(n)
set(gcf)
set(gca)
plot((5:5:300),mean(A,1)); % we take an average plot of
%the 300ms after all the 40 stimulations of the stimulated
%electrode.
title(['File: ' filename ' Stim electr: ' num2str(StimElectr(n))]);
xlabel('Latency [ms]'); ylabel('Count'); grid on
fpath='G:\test'
saveas(figure(n),fullfile(fpath,'PSTHPlots'),'bmp')
Any help appreciated! Thank you, Stella
  2 件のコメント
Marcus Tan
Marcus Tan 2021 年 8 月 29 日
Hi @Stelina I am working on a project that requires me to save multipl figure into bmp format to a named path. Really appreciate your advise if you could share with me how you do it. I tried following what u did by doing figure(n) but it keep giving me error.
dpb
dpb 2021 年 8 月 29 日
編集済み: dpb 2021 年 8 月 29 日
The <Answer> I gave below does work for the specific case; it's not possible to know where you went wrong without your code and error.
That probably would be more suitable as a new Question rather than follow-up here; one could hazard a guess you've used some other variable than n in a loop or the idea outlined needs to be tailored to your specific code rather than copied verbatim.

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

採用された回答

dpb
dpb 2014 年 4 月 26 日
...
saveas(figure(n),fullfile(fpath,'PSTHPlots'),'bmp')
They're all being saved in the location requested but you're not updating the file name so the end result is you're overwriting N-1 previous with the Nth.
You need to update the filename to a unique name for each; perhaps using some variant of the name you've created for the title above.
  1 件のコメント
Stelina
Stelina 2014 年 4 月 28 日
Yeap, I created a name that gets updated for every iteration by horzcat the num2str(filename) and num2str(StimElectr(n)) and it works, thank you!
Stella

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

その他の回答 (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