Borrar filtros
Borrar filtros

saving multiple figures to a named path

3 visualizaciones (últimos 30 días)
Stelina
Stelina el 26 de Abr. de 2014
Editada: dpb el 29 de Ag. de 2021
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 comentarios
Marcus Tan
Marcus Tan el 29 de Ag. de 2021
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 el 29 de Ag. de 2021
Editada: dpb el 29 de Ag. de 2021
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.

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 26 de Abr. de 2014
...
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 comentario
Stelina
Stelina el 28 de Abr. de 2014
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Printing and Saving en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by