MATLAB: Adjust the resolution of PNG plot image on a remote terminal

lowMATLABprintr2009bremoteresolutionterminalunix

Generated plot image files using MATLAB R2009b on a remote UNIX terminal are always a low resolution image. I tried using the resolution option of the "print" command but that does not change the resolution of the output image at all.
How can I increase the resolution of the generated image files?

Best Answer

When running MATLAB R2009b or any release prior to R2014b that uses HG1 in the UNIX terminal or in "nodisplay" mode, there is a known limitation on increasing the resolution of an image with the print command.
The PostScript and Ghostscript devices all function in "nodisplay" mode on UNIX. The graphic devices -djpeg, -dpng, -dtiff (compressed TIFF bitmaps) and -tiff (EPS with TIFF preview) work as well, but under "nodisplay" they use Ghostscript to generate output instead of using the drivers built into MATLAB. However, Ghostscript ignores the -r option when generating -djpeg, -dpng, -dtiff and -tiff image files and always uses the default resolution of 72DPI.
A workaround is to set the "PaperUnits" and "PaperPosition" of the figure to increase its size.
Workaround: 
% Example graph
plot(1:10)
% Set the "PaperUnits" and "PaperPosition" of the figure to increase its size
% Using [0 0 16 12] in "PaperPosition" creates an image that has the dimensions of 1152x864 pixels or (16*72) x (12*72) pixels
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 16 12])
% Print to the PNG file
print -dpng filename