MATLAB: How to save a figure as a ‘.bmp’ file in MATLAB 7.2 (R2006a) if the figure visible property is turned off

MATLAB

I execute the following commands in MATLAB 7.2 (R2006a):
peaks;
set(gcf,'visible','off');
saveas(gcf,'myfile.bmp');

Best Answer

The SAVEAS function uses the '-dbitmap' option to print, which works by performing a screen capture. Since the figure is invisible, the data cannot be captured.
To workaround this, use the PRINT command to save the figure as a BMP-file.
print (gcf, '-dbmp', 'myfile.bmp')