matlab djpegxx bug — problem calling ghostscript: system error 
Recently, I wrote Matlab code that does some processing, plots the results and saves the plots as compressed JPEGs. When I run it on a cluster as part of a batch job I got the following error: "Problem calling GhostScript. System returned error". Apparently Matlab releases prior to R2007a suffer from a bug to do with printing compressed JPEGs. Here is how to reproduce the above error. First, run Matlab as follows:
matlab -nodisplay
Or alternatively like so:
unset DISPLAY matlab -nodesktop -nosplash
The unset DISPLAY command simulates the non-interactive conditions that exist when you run a Matlab script from batch jobs using for example bash commands such as:
matlab -nodesktop -nosplash < job.m 2>&1 |tee ".log" matlab -nodisplay < job.m 2>&1 |tee ".log"
Once Matlab starts, type in the following.
>> figure >> print -djpeg70 'figure.jpg'
Running the above commands from Matlab release prior to R2007a produces the following errors.
??? Error using ==> graphics/private/ghostscript Error using ==> graphics/private/ghostscript Problem calling GhostScript. System returned error
To get around this problem you could a) update to Matlab R2007a or newer, b) disable JPEG compression as shown below,
>> figure >> print -djpeg 'figure.jpg'
or c) use a different image format, such as PNG, if appropriate.
>> figure >> print -dpng 'figure.png'
References:
- Matlab Bug Report: Cannot create a JPEG file specifying a quality setting in nodisplay mode on Linux
- Matlab Central: Printing high quality jpegs in batch mode
Hope this helps!
Did you find the above information useful and interesting? If so, please support this site by using the blog directory links at the bottom of this page. Thanks for your support!
If you have any Linux related problems or questions then please feel free to post them on our Linux Forums: http://linux.dsplabs.com.au/forums.
