MATLAB: Does the deployed application save a figure with incorrect resolution when the application is run as a cron job

MATLAB Compiler

I have written a script called 'PrintFigureToTiff.m' that creates a figure and then saves it in TIFF format:
f = figure;
set(f,'PaperUnits','centimeters','PaperSize',[15.5,11.5],'PaperPosition',[.0,.0,15.25,11.25]);
h(1) = axes('Position',[0 0 1 1]);
sphere;
h(2) = axes('Position',[0 0 .4 .6]);
sphere;
h(3) = axes('Position',[0 .5 .5 .5]);
sphere;
h(4) = axes('Position',[.5 0 .4 .4]);
sphere;
h(5) = axes('Position',[.5 .5 .5 .3]);
sphere;
set(h,'Visible','off');
print -dtiff -r200 image.tiff
I used the MATLAB Compiler 4.10 (R2009a) to build this script into a standalone application. When I run the standalone application on the target machine from the Unix shell console, the resolution of output image is 200*200 dpi as expected. However, when I run the executable as part of a cron job, the resolution of the output image becomes 72*72 dpi.
Why is the cron job saving to incorrect resolution?

Best Answer

This problem can occur if the shell that is launched via a cron job does not have the DISPLAY environment variable set. To resolve this issue, try setting the DISPLAY to some value, for example 0.0 or 0.5, as part of your cron job. Here is one such cron job:
* * * * * DISPLAY=:0.0;export DISPLAY;./PrintFigureToTiff