使用-nodisplay -nodesktop -nosplash打印Matlab数字

时间:2012-06-19 22:33:56

标签: plot maps matlab matlab-figure

我正在使用Matlab的Mapping Toolbox来创建和打印北美洲的圆锥形投影图。当我在IDE中运行代码时,打印并正确保存图表,但是当使用-nodisplay -nodesktop -nosplash在命令行上运行相同的脚本时,我遇到了一个非常奇怪的问题。

在print()函数调用期间,Matlab停止运行脚本,没有任何错误,警告或崩溃日志。 Matlab实际上并没有崩溃......它只是停止执行我的代码。如果可以打印没有显示的图形according to this

其他人遇到过类似的问题,并在MathWorks website上询问了这个问题。

Here is some code to reproduce this problem.

到目前为止,还没有人提出解决方案。有没有人有什么建议?提前谢谢!

编辑1:

以下是一些重现问题的自包含代码。我已经在R2011b和R2012a上进行了测试。

figure(1)
axesm eckert4; framem; gridm; axis off; tightmap

load geoid
contourfm(geoid, geoidrefvec, -120:20:100, 'LineStyle', 'none');

coast = load('coast');
geoshow(coast.lat, coast.long, 'Color', 'black')

contourcbar

print('-f1','-dpng','-r200','-painters', 'example');

2 个答案:

答案 0 :(得分:2)

如果使用例如

从脚本运行MATLAB,则会出现以下警告
#!/bin/sh
nohup matlab -nodisplay -nodesktop -r myCode > myLog.log &
exit  

[Warning: Objects of graph2d.lineseries class exist - not clearing this class or
any of its superclasses] 
[Warning: Objects of scribe.legend class exist - not clearing this class or any
of its superclasses] 
[Warning: Objects of graphics.panbehavior class exist - not clearing this class
or any of its superclasses] 
[Warning: Objects of graphics.zoombehavior class exist - not clearing this class
or any of its superclasses] 
[Warning: Objects of graphics.rotate3dbehavior class exist - not clearing this
class or any of its superclasses] 
[Warning: Objects of graphics.datacursorbehavior class exist - not clearing this
class or any of its superclasses] 
[Warning: Objects of graphics.ploteditbehavior class exist - not clearing this
class or any of its superclasses]

问题是matlab代码想要显示图形,图表或其他内容,但选项-nodisplay禁止它。我只需在代码set(gcf, 'visible','off');和结尾close gcf; clear gcf;添加以下行即可解决此问题。现在情节传说和没有转变的第一个情节一样,我没有得到任何警告。

答案 1 :(得分:1)

我得出的结论是,这个问题无法解决,而且是一个错误。

我最接近解决问题的方法是使用shell中的以下代码:

$ matlab -nosplash -nodisplay < makefigure.m

makefigure.m:

plot(randn(100,1)); 
set(gca,'Units','normalized','Position',[0.13 0.11 0.775 0.815]);
set(gcf,'Units','pixels','Position',[4 4 1200 900]);  %# Modify figure size
hgexport(gcf,'myfig.png',...
    hgexport('factorystyle'),'Format','png');

这将输出1200x900像素的png文件'myfig.png'。不幸的是,虽然图像是我想要的尺寸,但图形本身仍然是小尺寸。我不确定这个原因,但是我认为它与Matlab面向对象并且轴假设链接到图形大小这一事实有关(这就是什么gca的'Position'变量标准化为)。无论出于何种原因,当显示器关闭时,这不会发生。我怀疑Mathwoks很快就会解决这个问题,我不能责怪他们,因为绝大多数Matlab用户都使用GUI。

可以帮助任何人解决此问题的一个潜在线索是,它在命令行上运行时出错:

Warning: Objects of graph2d.lineseries class exist - not clearing this class
or any of its super-classes 

我搜索了一个解决方案但发现了更多问题。我怀疑如果有人能弄明白这意味着什么,你可以解决这个问题。现在,我将再次回到python,因为使用Matlab我只花费数小时处理不便而不是提高工作效率。

编辑: 如果它有帮助,这是Matlab 2012a Linux ... 2.6.35.6-45.fc14.x86_64#1 SMP ... x86_64 x86_64 x86_64 GNU / Linux