0
votes

I need to save all the figures that generated from one set of MATLAB code into one single pdf file instead having them in separate files.

X = rand(20,1);
Y = rand(20,1);
t=(1:20)';
figure(1);
plot(t,X);
saveas(gcf,'figure1.pdf');
figure(2);
plot(t,Y);
saveas(gcf,'figure2.pdf');
1
On what platform are you? There are tools to combine PDF files, I think you should use one of those. - Cris Luengo
I am using Matlab 2019a - Roxana
No, I mean do you use Windows, MacOS or Linux? - Cris Luengo
I use Windows :) - Roxana
Oh, sorry, that makes it hard. Maybe there’re good free PDF tools nowadays for Windows, I don’t know, I am not familiar any more with it. I could have helped you with Mac or Linux. My idea was to write the PDFs like you do now, then combine them into a single PDF using a tool outside MATLAB. - Cris Luengo

1 Answers

1
votes

Depending on your exact needs you could do something like,

close all
X = rand(20,1);
Y = rand(20,1);
t=(1:20)';

% Create a figure with enough room for two axes:
figure('Position',[600 400 600 800]);

ax1 = axes('Position',[0.1 0.06 0.85 0.43]); % Set axes 1 properties
plot(t,X); % Plot data 1
xlabel('x1'); ylabel('y1');
set(gca,'fontsize',14)

ax2 = axes('Position',[0.1 0.55 0.85 0.43]); % Set axes 2 properties
plot(t,Y); % Plot data 2
xlabel('x2'); ylabel('y2');
set(gca,'fontsize',14)

print -dpdf -bestfit Figure.pdf % Print figure to pdf with -bestfit property

You can add more axes and change their size by setting the properties of ax1 and ax2.