Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to save matlab figures to a specified directory

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?

like image 375
olamundo Avatar asked Oct 25 '11 12:10

olamundo


People also ask

How do I save a figure in MATLAB code?

To save the current figure, specify fig as gcf . saveas( fig , filename , formattype ) creates the file using the specified file format, formattype .

How do I save a mat in a different folder?

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 ...


1 Answers

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
like image 89
Aabaz Avatar answered Oct 25 '22 18:10

Aabaz