我正在尝试使用print
函数在Matlab中保存图像:
myImage = magic(500);
myFigure = figure('visible','off');
r = 1;
set(myFigure, 'PaperUnits', 'inches', 'PaperPosition', [0 0 1920 1080]/r);
% the program works fine on both computers without the line above
% however, the program runs fine on one computer only with this line
imagesc(myImage); axis image;
print(myFigure, '-dpng', sprintf('-r%d',r), 'myOutput.png');
当我使用Matlab R2012b在本地运行此程序时,它按预期工作。但是,如果我尝试在使用Matlab R2011b的远程计算机上运行它,我会收到以下错误消息:
Error using ghostscript (line 188)
Problem converting PostScript. System returned error: -1.Failed to convert to
output format; Ghostscript status: -100.**** Unable to open the initial device,
quitting.
以及由调用print()
的行触发的以下错误:
Error in print>LocalPrint (line 311)
pj = ghostscript( pj );
Error in print (line 237)
LocalPrint(pj);
代码更具体:
if pj.GhostDriver
pj = ghostscript( pj );
elseif strcmp( pj.Driver, 'hpgl' )
hpgl( pj );
end
在我的笔记本电脑上,pj.GhostDriver
为''
,pj.Driver
为png
。
一种可能的解释是我可以从终端本地启动ghostscript:
$ ghostscript
GPL Ghostscript 9.10 (2013-08-30)
Copyright (C) 2013 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
GS>
但不是从终端远程(因为我在远程计算机上没有任何图形界面):
$ ghostscript
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
GPL Ghostscript 9.05: Cannot open X display `(null)'.
**** Unable to open the initial device, quitting.
我原以为Matlab已经知道了,因为我使用以下方法在两台计算机上启动了Matlab:
matlab -nosplash -nodesktop -singleCompThread
此外,就终端而言,通过向~/.bashrc
添加以下行,可以轻松解决此问题:
export GS_DEVICE=display
任何解决方案的暗示?