Effacer les filtres
Effacer les filtres

savesas does not work as saveas in the menu

4 vues (au cours des 30 derniers jours)
Jan
Jan le 28 Août 2013
Commenté : hamed le 4 Déc 2020
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 commentaire
Jeff E
Jeff E le 24 Août 2017
Try adding the line below. It fixed my size discrepancy between "saveas" and using the menu.
h.PaperPositionMode='auto';

Connectez-vous pour commenter.

Réponses (3)

Iain
Iain le 28 Août 2013
Try using gcf with saveas, not gca.

Jan
Jan le 28 Août 2013
I tried h,gcf,gca, nothing changed the size of the saved figure.

Peter
Peter le 1 Août 2014
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 commentaire
hamed
hamed le 4 Déc 2020
Thanks peter,
It solved my problem as well.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by