10

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?

olamundo
  • 23,991
  • 34
  • 108
  • 149
  • 2
    very similar question: [How do I get the handles of all open figures in MATLAB](http://stackoverflow.com/questions/4540604/how-do-i-get-the-handles-of-all-open-figures-in-matlab) – Amro Oct 27 '11 at 04:24

1 Answers1

12

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
Aabaz
  • 3,106
  • 2
  • 21
  • 26
  • 1
    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','Color',[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. – AllenH Mar 28 '12 at 22:53