필터 지우기
필터 지우기

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 CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by