I need to automatically export figures from Matlab to PNG. My figure has a size of 600x200 px:
hFig = figure(1); set(hFig, \'Color\', [1 1 1]); % background
Amro answer works perfectly, after you generate your figure, set PaperPositionMode to auto and the print size will be the same as screen size.
PaperPositionMode
auto
set(gcf, 'PaperPositionMode','auto') print('-dpng','test.png')