一次保存多个图形

问题描述 投票:0回答:1

我需要将一组MATLAB代码生成的所有图形保存到一个pdf文件中,而不是将它们保存在单独的文件中。

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');
matlab matlab-figure
1个回答
0
投票

根据您的确切需求,您可以执行类似的操作,

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

您可以通过设置ax1ax2的属性来添加更多轴并更改其大小。

© www.soinside.com 2019 - 2024. All rights reserved.