将多个图形保存在一个 pdf 中
Save multiple figures in one pdf
我正在尝试 save/combine 在一个 pdf 文件中循环创建的所有现有图形,而不是多个 pdf。让我们说每页一个数字。
x = rand(5,100);
y = rand(5,100);
for i = 1:5
plot(x(i,:), y(i,:));
filename_string = ['Plot_Number_', num2str(i),'_' ,'pdf'];
print(gcf, '-dpdf', '-r600', filename_string);
saveas(gcf,'testx', 'pdf');
end
- 在每个地块上添加
figure
,这将使每个地块位于不同的位置
window
- 制作
filename_string
剧情标题
- 用图命名代码,即
filename.m
- 再做一个m文件,比方说
main.m
- 使用
publish(filename', options)
获取pdf文件filename.pdf
- 在使用
publish
之前定义options
options.format = 'pdf'
options.showCode = false
Run main.m
and check the current directory you may see an HTML directory
where you can find the pdf file named filename.pdf
代码如下
filename.m
close all
clear
clc
x = rand(5,100);
y = rand(5,100);
for i = 1:5
figure% keep plots on different windows
plot(x(i,:), y(i,:));
title(['Plot Number ', num2str(i)], 'color', 'red', 'fontSize', 25)
end
main.m
close all
clear
clc
options.format = 'pdf';
options.showCode = false;
publish('filename.m', options)
使用子图?
x = rand(5,100);
y = rand(5,100);
figure();
for i = 1:5
subplot(1,5,i); hold on;
plot(x(i,:), y(i,:));
title(['Plot_Number_', num2str(i)]);
end
filename_string = ['Plots','_' ,'pdf'];
print(gcf, '-dpdf', '-r600', filename_string);
saveas(gcf,'testx', 'pdf');
我正在尝试 save/combine 在一个 pdf 文件中循环创建的所有现有图形,而不是多个 pdf。让我们说每页一个数字。
x = rand(5,100);
y = rand(5,100);
for i = 1:5
plot(x(i,:), y(i,:));
filename_string = ['Plot_Number_', num2str(i),'_' ,'pdf'];
print(gcf, '-dpdf', '-r600', filename_string);
saveas(gcf,'testx', 'pdf');
end
- 在每个地块上添加
figure
,这将使每个地块位于不同的位置 window - 制作
filename_string
剧情标题 - 用图命名代码,即
filename.m
- 再做一个m文件,比方说
main.m
- 使用
publish(filename', options)
获取pdf文件filename.pdf
- 在使用
publish
之前定义options
options.format = 'pdf'
options.showCode = false
Run
main.m
and check the current directory you may see an HTML directory where you can find the pdf file namedfilename.pdf
代码如下
filename.m
close all
clear
clc
x = rand(5,100);
y = rand(5,100);
for i = 1:5
figure% keep plots on different windows
plot(x(i,:), y(i,:));
title(['Plot Number ', num2str(i)], 'color', 'red', 'fontSize', 25)
end
main.m
close all
clear
clc
options.format = 'pdf';
options.showCode = false;
publish('filename.m', options)
使用子图?
x = rand(5,100);
y = rand(5,100);
figure();
for i = 1:5
subplot(1,5,i); hold on;
plot(x(i,:), y(i,:));
title(['Plot_Number_', num2str(i)]);
end
filename_string = ['Plots','_' ,'pdf'];
print(gcf, '-dpdf', '-r600', filename_string);
saveas(gcf,'testx', 'pdf');