Script to save matlab figures to a specified directory

12,677

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
Share:
12,677
olamundo
Author by

olamundo

Updated on July 19, 2022

Comments

  • olamundo
    olamundo almost 2 years

    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?

  • AllenH
    AllenH about 12 years
    I like this little function- works well. I'd love it to take the figure Name property as the figure "name".fig. You can set the name property quite easily with a similar command: figure('Name','ah3187w2070degspec1','NumberTitle','off','Col‌​or',[1 1 1]) Note that I also turn off the number in the title as well as set the figure background color in that code.