【问题标题】:Save Matlab invisible plot under terminal as an image with same size将终端下的Matlab不可见图保存为相同大小的图像
【发布时间】:2010-12-23 14:53:49
【问题描述】:

我正在通过 SSH 连接到 Linux 服务器并进行一些 MATLAB 编程。我想将不可见的情节另存为

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() 也不起作用。 我想知道如何解决这些问题? 谢谢和问候!

【问题讨论】:

  • 您是否正在运行 X 服务器?

标签: matlab command-line save plot


【解决方案1】:

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

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

然后一个简单的情节来说明:

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

我自己试了一下,效果如预期。


编辑:

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

print -dpdf -r600 file.pdf

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

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

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

【讨论】:

  • 问题是使用 saveas() 或 print() 不会保留保存的图像大小与绘图相同。
  • 在您之前的问题中不是已经解决了吗:stackoverflow.com/questions/1848176/…
  • 那里提供的解决方案实际上不适用于终端模式和 Matlab 不可见图(我接受它只是因为它适用于 X 模式和 Matlab 可见图)。特别是 getframe() 将返回 null 即使您建议连接到服务器并运行 Matlab 的方式。
  • 感谢 Amro!这解决了我的问题!只是好奇: (1)“figure, close”的目的是什么,它与“figH = figure('visible','off')”的区别是什么? (2)"unset DISPLAY"的作用是什么,和"ssh -X"的组合是什么?
  • 1) 这只是为了防止错误 og 在保存的文件中出现空图:mathworks.com/support/solutions/en/data/1-15HNG/index.html 2) 我用这些来表明您没有在 X 模式下运行。 ssh -x(小 x!)禁用 X11 转发,然后我们清除指定用于图形输出的设备/主机的 DISPLAY 环境变量。通常只需使用 -nodisplay 选项启动 MATLAB 就足够了..
猜你喜欢
  • 1970-01-01
  • 2012-10-22
  • 2013-11-13
  • 2021-05-11
  • 2011-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多