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

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

问题描述

我需要自动将图形从 Matlab 导出到 PNG.我的图的大小为 600x200 像素:

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

我试过例如

print -dpng image.png

但 image.png 大于 600x200 像素.使用保存"按钮从图形窗口 GUI 手动导出图形效果很好,我想自动/从脚本执行此操作.感谢您的任何提示!

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.

saveas 命令可能对您有用 - 但也会为我更改一些分辨率.

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')

(因此纸张尺寸为 2x6" 并以 100dpi 打印,PaperPosition 很重要,否则您将有一些额外的边框.)

(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天全站免登陆