The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: saving current figure?
Replies: 7   Last Post: Jul 27, 2012 4:29 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Oliver Woodford

Posts: 615
Registered: 8/3/07
Re: saving current figure?
Posted: Jul 27, 2012 4:29 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Jessica" wrote:
> > "Jessica" wrote in message <jupo0m$kdk$>...
> > > Hi,
> > >
> > > Can anyone give suggestions about how to save the current figure with a specified DPI AND save it with the same dimensions it shows according to the axis. My current figure is 96 dpi and 1280 x 1024 pix and I want to save this (as a .jpg or .bmp) with the same properties. I also don't want to save the extra border around the figure (that is outside the figure handle).
> > >
> > > Thanks

> >
> > export_fig ( does this if you save as png or tiff.

> The figure I load is 1280 x 1024. When I save it with:
> export_fig test3.png -r96
> It outputs a figure with 96 dpi but with 684x547.
> When I save it with:
> export_fig test3.png -r96 -m2 or export_fig test3.png -r48 -m2
> It outputs a figure with 180 dpi and 1281 x 1025.
> Any suggestions for getting it to 96 dpi and 1280 x 1024?

Hi Jessica

In MATLAB your figure doesn't have a dpi, only your screen does, and this is the dpi that export_fig uses. On my system the dpi is:
>> dpi = get(0, 'ScreenPixelsPerInch')

dpi =


So when I do:
>> figure('position', [0 0 1280 1024]);
>> plot(rand(3));
>> Filename = 'test.png';
>> export_fig(Filename, '-a1', '-nocrop');

the output is a png with a dpi of 96 and a size of 1280x1024, just as you want, and export_fig works as expected.

Given that export_fig returns an image with a dpi of 96 on your system, it must also have its dpi correctly set to 96. Therefore the only conclusion I can come to is that your figure is not 1280x1024, as you claim, but is smaller. Perhaps you are getting confused between figure size and resolution of an image in a figure - there is a big difference.

If you want to export a figure at 1280x1024 and 96dpi you need to set the figure size to 1280x1024 using:
>> set(gcf, 'Position', [0 0 1280 1024]);
before resaving the figure.


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.