Saving Custom Sized Graphs in MATLAB

10 ビュー (過去 30 日間)
Berk Ustun
Berk Ustun 2011 年 6 月 28 日
I have recently been trying to create a custom-sized graph in MATLAB and save it automatically using the saveas function. I am having issues saving the files in the size that I create them.
Roughly speaking, my code is as follows:
mygraph = figure('Position',[1,20,1280,1024]);
%creates a figure positioned 1 px from the left of the screen, 20 px from the bottom of the screen, that is 1280 px in length and 1024 px in height
% some code to create graph
saveas(mygraph,'mygraphfilename','emf')
% saves figure as mygraphfilename.emf.
So far, the code above can create a custom-sized graph on my screen, but it seems to save the pictures in a default size. The weird thing is that if I do not use the saveas function and save the figure manually, then the image retains its size.
For clarification purposes, I'm currently saving the graphs as emf, though I'm also open to using jpg/png/bmp if works fine too.

採用された回答

Patrick Kalita
Patrick Kalita 2011 年 6 月 28 日
I would suggest two things. First, use the print command instead of saveas because it gives you more control. Second, use the PaperPosition property instead of Position to control how big the exported graphic is.
Here's a quick example of exporting a 1280-by-1024 PNG-file:
% Draw your scene
plot(1:10);
% Control the output size using 'PaperPosition' -- note the 200 here... that will show up again as our output resolution.
set(gcf, 'PaperUnits', 'inches', 'PaperPosition', [0 0 1280 1024]/200);
% Note the -r200 -- we're telling it to export at 200 pixels-per-inch
print -dpng -r200 MyGraph.png
I tried the same thing with the -dmeta option (for generating an EMF-file), but it, err, didn't create the right size file. I think that might be because EMF -- since it can include both vector and bitmap content -- doesn't honor the pixels-per-inch setting the same way as a purely bitmap format.
  1 件のコメント
Berk Ustun
Berk Ustun 2011 年 6 月 28 日
Thank you for this! Using print definitely works with png/bmp files so that solves my issue, though I'll try some of the vector based graphics contained in the export_fig package.

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 6 月 28 日
Please try the MATLAB File Exchange contribution export_fig .
  1 件のコメント
Berk Ustun
Berk Ustun 2011 年 6 月 28 日
Fantastic!

サインインしてコメントする。


Chetan Rawal
Chetan Rawal 2012 年 10 月 16 日
編集済み: Chetan Rawal 2012 年 10 月 16 日
There is more insight on custom printing for dimensions in the following link:
http://www.mathworks.com/support/solutions/en/data/1-16WME/index.html?product=ML&solution=1-16WME

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by