我正在尝试将所有在循环中创建的现有图形保存/合并到一个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
答案 0 :(得分:1)
figure
,这将使每个图保持不同
窗口filename_string
剧情标题filename.m
main.m
publish(filename', options)
获取pdf文件filename.pdf
publish
之前,先定义options
options.format = 'pdf'
options.showCode = false
运行
的pdf文件main.m
并检查当前目录,您可能会看到一个 HTML 目录 您可以在其中找到名为filename.pdf
文件名.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)
答案 1 :(得分:0)
使用子图吗?
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');