Is there a way to dynamically save a plot figure into a jpeg file without having to type the filename i would be saving it into?
Afficher commentaires plus anciens
I am executing a code that generates a plot figure, which I save using the following command: print '-djpeg' '-f2' '-r300' _f2
Where _f2 is literally the name of the jpeg I will be saving my plot into.
I wonder if there's a way of doing this dynamically, what i mean is that instead of entering the file name literally I could pass a string containing the file name, so I can execute this could without having to type each time the file name in my code.
As a previous step to generating the plot figure, I load a file and analyze it. Each file is identified with a frequency (filename=06000). My idea is to copy the filename (06000) into a string, so i can identify each jpeg with its corresponding file (06000.jpeg)
Thanks!!
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 18 Août 2012
Modifié(e) : Image Analyst
le 18 Août 2012
Use sprintf() to construct your filename and then use export_fig() to save it:
baseFileName = sprintf('F%s_h%s.jpg', numberId, numberId);
fullFileName = fullfile(yourFolder, baseFileName);
export_fig(figureHandle, fullFileName); % Best way.
saveas(figureHandle, fullFileName); % Alternative way
2 commentaires
Laura
le 18 Août 2012
Image Analyst
le 18 Août 2012
It look like you just ran the code and didn't read the FAQ. In the FAQ it explains how you can download export_fig. Anyway, here is the direct link: http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig Or you can go to the front page of the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/ because it's always the most downloaded submission every month.
Jürgen
le 18 Août 2012
1 vote
Hi,
with e.g.: freq=1 time=103 Filename = ['F' num2str(freq) '_h' num2str(time) '.jpg'] =>Filename =F1_h103.jpg then saveas(gcf, Filename)
this should work
regards,J
5 commentaires
Laura
le 18 Août 2012
Jürgen
le 21 Août 2012
Hi then it is easier, because you can use the string directly :
freq='1', time='103', Filename = ['F' freq '_h' time '.jpg'] then use the saveas
Laura
le 3 Sep 2012
Sina Zinatlou
le 24 Mar 2021
Image Analyst
le 24 Mar 2021
That was from 9 years ago. Now you can use the new exportgraphics() function.
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!