MATLAB export figure to .png changes size after export

4 次查看(过去 30 天)
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 个评论
Fernon Ejikhoudt
Fernon Ejikhoudt 2018-7-29
编辑:Fernon Ejikhoudt 2018-7-29
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by