フィルターのクリア

savesas does not work as saveas in the menu

4 ビュー (過去 30 日間)
Jan
Jan 2013 年 8 月 28 日
コメント済み: hamed 2020 年 12 月 4 日
Hi all,
I do not find a solution to the following problem. I want to save a figure automatically from the code. I tried saveas and print as well. I noticed that the saveas command does not work as the saveas which I can select from the figure menu. I run the following code to save my figure:
fileName='test';
h=figure;
%...other plotting code
set(h,'units','normalized','outerposition',[0 0 1 1])
drawnow;
saveas(h,[fileName '.png']);
saveas(h,[fileName '.fig']);
The point is. If I run saveas from the menu and select png. The figure is stored with full screen resolution. If I run the code it is not stored with full screen resolution although the figure is automatically maximized by the code. Using other ways of maximizing the figure did not change the resolution of the png image e.g. set(gcf, 'Position', get(0,'Screensize')).
print('-dpng','-r300','test') will only increase the rate the screen is sampled but not the size of the figure.
The most weird thing is, that saveas does not behave similar to the save as in the menu, I get different resolutions using saveas and the saveas from the menu although I do no change on the figure.
best regards Jan
  1 件のコメント
Jeff E
Jeff E 2017 年 8 月 24 日
Try adding the line below. It fixed my size discrepancy between "saveas" and using the menu.
h.PaperPositionMode='auto';

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

回答 (3 件)

Iain
Iain 2013 年 8 月 28 日
Try using gcf with saveas, not gca.

Jan
Jan 2013 年 8 月 28 日
I tried h,gcf,gca, nothing changed the size of the saved figure.

Peter
Peter 2014 年 8 月 1 日
I had a similar problem. Below is the answer I got that fixed it.
Answer by Namita Vishnubhotla on 31 Jul 2014 at 13:58 Accepted answer
The following code resolves the figure resizing issue:
>> set(fig, 'PaperPositionMode', 'auto');
where 'fig' is your figure handle. You can also just pass 'gcf'.
The 'PaperPositionMode' property (as published in documentation) "ensures that the printed version is the same size as the onscreen version. With 'PaperPositionMode' set to 'auto' MATLAB does not resize the figure to fit the current value of the 'PaperPosition'."
Refer to the various properties listed in the figure properties and axes properties documentation for additional saving and printing settings that may affect the look of your figure when exporting to printer or file.
  1 件のコメント
hamed
hamed 2020 年 12 月 4 日
Thanks peter,
It solved my problem as well.

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

カテゴリ

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