Export plot as 600dpi png and with variables in the file name

5 次查看(过去 30 天)
iter = 1;
for i=1:10
t =1:1:1000;
p =t*i;
figure
plot(t,p,'Color', 'b','LineWidth',2)
hold on
set(gca,'FontWeight','bold','FontSize',18)
%Works if
%print(gcf,'p.png','-dpng','-r600');
print(gcf,'p%s.png',iter,'-dpng','-r600');
end
How to export figure with a name variable in the filename and 600dpi. Thanks!

采纳的回答

Jan
Jan 2022-12-18
编辑:Jan 2022-12-18
print(gcf, sprintf('p%d.png', iter), '-dpng', '-r600');
% [EDITED], %s -> %d
  1 个评论
Miraboreasu
Miraboreasu 2022-12-18
编辑:Miraboreasu 2022-12-18
Thanks, but Error using matlab.graphics.internal.name Unable to create output file '.\p.png', Invalid argument.
fixed by
print(gcf, sprintf('p%d.png', iter), '-dpng', '-r600');

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Filter Analysis 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by