Matlab中带打印函数的重影脚本错误

Matlab中带打印函数的重影脚本错误,matlab,printing,save,png,ghostscript,Matlab,Printing,Save,Png,Ghostscript,我正在尝试使用打印功能在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 pr

我正在尝试使用
打印
功能在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');
当我用MatlabR2012B在本地运行这个程序时,它可以正常工作。但是,如果我尝试使用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>
但不是从终端远程(因为我在远程计算机上没有任何图形界面):

我本以为Matlab已经知道了这一点,因为我使用以下方法在两台计算机上启动Matlab:

matlab -nosplash -nodesktop -singleCompThread
此外,通过在
~/.bashrc
中添加以下行,就终端而言,此问题很容易解决:

export GS_DEVICE=display


有什么解决方案吗?

您可以使用
print
执行的大多数操作您也可以使用
saveas
执行-也许您很幸运,因为保存到png不需要ghostscript。如果不查看函数,我猜
print
会自动使用ghostscript进行打印,然后将其转换为png。
-dpng
根据
print
函数的帮助,不应该使用
ghostscript
。此外,
saveas
也不能更好地工作。罪魁祸首是以
set(myFigure,…)开头的行
我可能已经找到了这个工具箱的解决方案:我所做的是使用
-m
选项来放大分辨率。
export GS_DEVICE=display