The following script using Xvfb works well for me for SPM5. I name it as matlab.sh and call it from the terminal. You can test the output using "import" command from Imagemagick. Obviously you may change the screen resolution to your like. When you exit matlab, Xvfb process will be killed.
Xvfb :1 -screen 0 1680x1050x16 &
DISPLAY=:1 matlab -nodesktop -nojvm -nosplash
# In another terminal run the following to capture the display
# DISPLAY=:1 import -window root temp.png