将终端下的Matlab隐形图保存为相同大小的图像

将终端下的Matlab隐形图保存为相同大小的图像

本文介绍了将终端下的Matlab隐形图保存为相同大小的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 SSH 连接到 Linux 服务器并进行一些 MATLAB 编程.我想将隐形情节保存为

I am SSH connecting to a Linux server and do some MATLAB programming. I would like to save invisible plot as

figH = figure('visible','off') ;
% Plot something
% save the plot as an image with same size as the plot
close(figH) ;

saveas()print() 将改变保存图像的大小而不是绘图的大小.同样对于 print(),所有三种渲染器模式(-opengl-ZBuffer-painters)都不能在 Linux 服务器上以终端仿真模式使用.getframe() 也不起作用.我想知道如何解决这些问题?感谢和问候!

saveas() and print() will change the size of the saved image different than the size of plot. Also for print(), all three renderer modes (-opengl, -ZBuffer and -painters) can not be used in terminal emulation mode on the Linux server. getframe() doesn't work either.I wonder how I can solve these problems?Thanks and regards!

推荐答案

使用以下命令序列连接并启动 MATLAB:

Use the following sequence of commands to connect and start MATLAB:

ssh -x user@server          # disabled X11 forwarding
unset DISPLAY               # unset DISPLAY variable
matlab -nodisplay           # start MATLAB without the desktop

然后用一个简单的图来说明:

then a simple plot to illustrate:

figure, close                    # must do this first, otherwise plot is empty
plot(1:10)                       # usual plotting
print file                       # save the figure as file.ps
saveas(gcf, 'file.eps', 'eps2c') # saveas aslo works
exit                             # done

我只是自己尝试过,它按预期工作.

I just tried it myself, and it works as expected.

您始终可以使用 -r 指定 DPI 分辨率,例如非常高的分辨率:

You can always specify the DPI resolution using -r<number>, for example a very high resolution:

print -dpdf -r600 file.pdf

请注意,您可以使用 -r0 来指定屏幕分辨率.

Note that you can use -r0 to specify screen resolution.

您也可以使用 PaperPositionMode 属性打开所见即所得的图形打印:

Also you can turn on WYSIWYG printing of figures using the PaperPositionMode property:

figure, close
plot(1:10)
set(gcf, 'PaperPositionMode', 'auto')
print -deps2c -r0 file.eps
exit

这篇关于将终端下的Matlab隐形图保存为相同大小的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 13:23