Reputation: 71
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');
Upvotes: 0
Views: 962
Reputation: 1325
If this question turned up in your search result, MATLAB version newer than R2020a can save multiple figures in one PDF file with the following command and switch:
exportgraphics(ax,'myplots.pdf','Append',true)
Upvotes: 0
Reputation: 800
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
.
Upvotes: 1