savesas does not work as saveas in the menu
조회 수: 3 (최근 30일)
이전 댓글 표시
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
2017년 8월 24일
Try adding the line below. It fixed my size discrepancy between "saveas" and using the menu.
h.PaperPositionMode='auto';
답변 (3개)
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!