Saving multiple figures all at once

16 views (last 30 days)
Adrian
Adrian on 2 Apr 2012
I am running a program that generates 50+ figures.
First: Is there a way where I can resize the viewing window for all of the figures without doing it one at a time?
Second: Is there a way I can save them all at once into a PDF? Doing 'File -> Save as...' for each figure gets time consuming.
thanks!
Adrian

Answers (1)

Geoff
Geoff on 2 Apr 2012
You'll want to do it in a loop. First, make sure you have stored the handles to your figures in a vector.
figures = [];
% Generate figures
%[your code]
% Resize and output figures
figSize = [21, 29]; % [width, height]
figUnits = 'Centimeters';
for f = 1:numel(figures)
fig = figures[f];
% Resize the figure
set(fig, 'Units', figUnits);
pos = get(fig, 'Position');
pos = [pos(1), pos(4)+figSize(2), pos(3)+figSize(1), pos(4)];
set(fig, 'Position', pos);
% Output the figure
filename = sprintf('Figure%02d.pdf', f);
print( fig, '-dpdf', filename );
end
You can read more about the print command here:
doc print

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!