Matlab plots with a very low resolution when using -nodesktop option

I'm having trouble with the resolution of matlab plots when the function is run via a cronjob using the -nodesktop option. The function plots, and saves (using the print function) a number of figures. When run from the matlab desktop, they plot and save according to the specified resolutions with no problems. But when run via a cronjob with the -nodesktop option, the resolutions are very poor (low).

This is essentially what I'm currently doing:

fh = figure;

set(fh,'Position',[0 0 1360 470]);



Note that I've also tried specifying a print resolution:


But this ends up with corrupt files. I'm not sure why. I'm using -painters because I read somewhere that if the plot is somewhat complicated it can default to opengl which ruins prints but this doesn't seem to be the issue (with or without the option, the plots are the same).

I've also tried:


which does not solve the problem.

The cronjob runs the following command:

/usr/local/bin/matlab -nodesktop -r "startup; perform_plots; exit"

Any help would be much appreciated!


I figured out the issue.

By running matlab as a cronjob, the DISPLAY environmental variable wasn't set. As a result there was no X display for matlab to utilise. I don't know how it still managed to plot anything at all but it did and did so with a very low resolution.

The solution is to set the appropriate display before hand. e.g.:


export DISPLAY=:1.0

/usr/local/bin/matlab -nodesktop -r "startup; perform_plots; exit"

In case you want to run it on a box that doesn't have an X server, you can set up a dummy X server using Xvfb (X virtual frame buffer). This also has the advantage of using a display separate to the one you may be working on so jobs can run in the background without plots randomly appearing while you work.

Need Your Help

Putting a password to a user in PhpMyAdmin in Wamp

phpmyadmin wampserver

How do you change the password for the root user in phpMyAdmin on WAMP server? because I'm locked out of phpMyAdmin, after changing the password incorrectly.

Access ng-model from one div to another div

javascript html angularjs

I want to access ng-model value from one div to another div.