Suppose I have several figures open in matlab. I would like some function I can call, e.g save_all_figures_to_directory('dir_name')
, that would iterate over all figures and save them to the specified folder. How do I do this?
To save the current figure, specify fig as gcf . saveas( fig , filename , formattype ) creates the file using the specified file format, formattype .
mat . To save to another directory, use the full pathname for the filename . If filename is the special string stdio , the save command sends the data as standard output. save filename var1 var2 ...
You can use the Matlab function findobj
:
function save_all_figures_to_directory(dir_name)
figlist=findobj('type','figure');
for i=1:numel(figlist)
saveas(figlist(i),fullfile(dir_name,['figure' num2str(figlist(i)) '.fig']));
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With