导出Matlab图为PNG? [英] Export Matlab figure as PNG?

查看:675
本文介绍了导出Matlab图为PNG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要自动将Matlab导出到PNG。我的数字大小为600x200像素:

  hFig = figure(1); 
set(hFig,'Color',[1 1 1]); %backgroundcolor white
set(hFig,'Position',[500 500 600 200])%size 600x200


$ b $我尝试过例如

  print -dpng image.png 

,但image.png大于600x200像素。使用保存按钮从图形窗口GUI手动导出图形非常好,我想从脚本中自动执行。感谢任何提示!

解决方案

我也知道数字保存的问题与屏幕上看起来一样。



有可能为您工作的 saveas 命令,但也有一些解决方案改变了我。



只有我知道的方法是仔细设置每个方面:

  set(gcf, 'PaperUnits','inches','PaperSize',[2,6],'PaperPosition',[0 0 2 6])
print(' - dpng',' - r100','test' b $ b

(所以纸张尺寸为2x6,打印为100dpi,PaperPosition非常重要,边框。)


I need to automatically export figures from Matlab to PNG. My figure has a size of 600x200 px:

hFig = figure(1); 
set(hFig, 'Color', [1 1 1]); % backgroundcolor white
set(hFig, 'Position', [500 500 600 200]) % size 600x200

I tried e.g.

print -dpng image.png

but the image.png is larger than 600x200 px. Exporting the figure manually from the Figure Window GUI using the "save" button works great, I want to do exactly this automatically / from a script. Thanks for any hint!

解决方案

I also know the problem that figures save never look the same as on screen.

There is the saveas command which might work for you - but does also some resolution changing for me.

Only way I know is to carefully set every aspect like this:

set(gcf,'PaperUnits','inches','PaperSize',[2,6],'PaperPosition',[0 0 2 6])
print('-dpng','-r100','test')

(so paper size is 2x6" and print with 100dpi, PaperPosition is important as you will have otherwise some extra border.)

这篇关于导出Matlab图为PNG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆