MATLAB: Do I receive an error when I attempt to run a stand-alone MATLAB graphics application on Linux as part of a CRON job

applicationcc/c++crondisplaygraphicgraphicslibraryMATLABMATLAB Compilerstand-alonestandaloneunixvncx

Why do I receive an error when I attempt to run a stand-alone MATLAB graphics application on Linux as part of a CRON job?
When I attempt to run a stand-alone MATLAB graphics application as part of a cron job on Linux, I receive the following error message:
C/C++ Graphics Library applications require that a DISPLAY be
available.
EXITING

Best Answer

This problem occurs because the X display, which is required by the MATLAB C/C++ Graphics Library, becomes disabled when the cron job is running and no one is logged on the machine.
Currently, to work around this issue, try the following:
Start a VNC server on your computer and exploit the fact that UNIX machines will think that the VNC server is an actual X display. In fact, you can start the VNC server as part of the cron job that runs the stand-alone MATLAB graphics application.
For more information about VNC, you can reference the University of Cambridge AT&T Lab Web site or any other Web site offering VNC distributions.
Alternatively, if a display is expected to be available when this cron job runs, the DISPLAY environment variable can be set as below (in this case, it is set to the default local display of the user)
DISPLAY=:0.0
SHELL=/bin/bash
PATH=$PATH:/usr/X11R6/bin
# Run jobs run in an xterm
00 5 * * *xterm -e <path to MATLAB script file>