Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: saving current figure?
Posted:
Jul 27, 2012 4:29 AM
|
|
"Jessica" wrote: > > "Jessica" wrote in message <jupo0m$kdk$1@newscl01ah.mathworks.com>... > > > 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 (http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig) 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 =
96
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.
HTH, Oliver
|
|
|
|