MATLAB export figure to .png changes size after export

4 views (last 30 days)
In my script I create about 30 figures which are automatically saved as MATLAB .fig and as .png. For my report I sometimes need to change the aspect ratio (instead of the standard 900x900 pixels, I want to have 1600x1000). That is why I save them as .fig as well. Once opening one of these figs I go to export setup and change the size in width and height in points. I press aplly and export as png. However once I look back at my figure it has suddenly become 1924x1007. I have no clue where this is coming from.
I hereby include my figure saving procedure, though I doubt this should have any effect:
amountFigures = findobj('type','figure');
for k = 1:length(amountFigures)
set(figure(k),'PaperPosition',[0 0 (900/300)/0.393701 (900/300)/0.393701]); %Sets a high quality output to the image
set(findobj(gcf,'type','axes'),'FontSize',14); %A bigger fontsize is needed for better readability
hline = findobj(gcf, 'type', 'line');
set(hline,'Linewidth',2);
temp = get(gca);
titel = temp.Title.String;
temp.Title.String = [];
savefig([titel,'.fig'])
print(gcf,'-dpng','-r300',[titel]); %Saves the figures with the titel name.
close(figure(k))
end
  1 Comment
Fernon Ejikhoudt
Fernon Ejikhoudt on 29 Jul 2018
Edited: Fernon Ejikhoudt on 29 Jul 2018
Soo, an update: if I would set it to centimeters and use 23.8 cm, it gives me exactly 900 pixels and 39.68 is 1500 pixels (1 pixel ~ 0.02645). This works, but it is still no excuse for the change in size when 'points' is selected instead of centimeters.

Sign in to comment.

Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!