Ghostscript error with print function in Matlab

匿名 (未验证) 提交于 2019-12-03 01:39:01

问题:

I am trying to save images in Matlab by using the print function:

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');

When I run this program locally with Matlab R2012b, it works as expected. However, if I try to run it on a remote machine with Matlab R2011b, I get the following error message:

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.

and the following error which is triggered by the line with the call to print():

Error in print>LocalPrint (line 311)         pj = ghostscript( pj );  Error in print (line 237)     LocalPrint(pj);    

The code is more specifically:

if pj.GhostDriver     pj = ghostscript( pj );  elseif strcmp( pj.Driver, 'hpgl' )     hpgl( pj ); end

On my laptop, pj.GhostDriver is '' and pj.Driver is png.


One possible explanation is that I can launch ghostscript locally from the terminal:

$ 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>

but not remotely from the terminal (since I do not have any graphical interface on the remote computer):

$ 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.

I would have thought Matlab already knew about it, since I launch Matlab on both computers by using:

matlab -nosplash -nodesktop -singleCompThread

Moreover, this problem is easily fixed as far as the terminal is concerned by adding the following line to ~/.bashrc:

export GS_DEVICE=display

Any hint at a solution?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!