Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Save figure as seen on screen?

Asked by C

C (view profile)

on 25 Jan 2013

I would like to save a figure to png format exactly the same as seen on the screen. I searched the web and found:

set(gcf,'PaperPositionMode','auto'); saveas(gcf,[Filename '.png']);

that supposed to save the figure the same size, but it actually changed the size from 1200x600 to 1875x938, huh?

I also tried setting ‘PaperPosition’ and got the same size 1200x600, but the fonts in the saved figure became much larger compared to on screen and covered up parts of the graph.

If I use the "save" button in the figure window then it saves the figure as seen on the screen without a problem, but I would like to be able to do it programmatically if possible.

Please help. Thanks!



C (view profile)


2 Answers

Answer by Jan Simon

Jan Simon (view profile)

on 25 Jan 2013
img = getframe(gcf);
imwrite(img.cdata, [FileName, '.png']);


Jan Simon

Jan Simon (view profile)

Answer by John Petersen

John Petersen (view profile)

on 25 Jan 2013

It's the same ratio at least. You may want to look at using export_fig() which you can download from the file exchange. This will preserve the figure size.

1 Comment

Image Analyst

Image Analyst (view profile)

on 25 Jan 2013

As mentioned in the FAQ: While you're reading that C, might as well look over the rest of the FAQ also.

John Petersen

John Petersen (view profile)

Contact us