saveas commad saves a figure with different size in MATLAB version 2013b and 2020b
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sajid Afaque
el 18 de En. de 2022
Editada: Richard Quist
el 23 de En. de 2022
Hi,
I recently switched from MATLAB 2013b to 2020b. I have a issue of figure size when saving figures as png.
I’ll try to illustrate my code
% This function automatically access the current Monitor Resolution and
% creates the plot graphs within this resolution
%%
intVecMonitorResolution = get(0,'MonitorPositions');
if intVecMonitorResolution(3) > 450
intScaWidth = intVecMonitorResolution(3)*0.8;
intScaLeftVal =intVecMonitorResolution(3)*0.1;
else
intScaLeftVal = 1;
intScaWidth = intVecMonitorResolution(1,3);
end
if intVecMonitorResolution(4) > 200
intScaHeight = intVecMonitorResolution(4)*0.75;
intScaBottomVal =intVecMonitorResolution(4)*0.1;
else
intScaBottomVal = 1;
intScaHeight = intVecMonitorResolution(1,4);
end
monitor_pos = [intScaLeftVal intScaBottomVal intScaWidth intScaHeight];
%%my monitor_pos
% monitor_pos =
% 1.0e+03 *
% 0.1536 0.0864 1.2288 0.6480
%%Plot something
x = 1:1:5;
y = 1:1:5;
fh=figure('Position',monitor_pos,'Visible','on');
set(0,'DefaultFigureColor','w');
ax=axes('parent',fh,'FontWeight','demi','FontSize',12,'FontName','Times New Roman','LineWidth',2,'TickDir','out');
plot(x,y,'r');
set(ax,'XMinorGrid','on')
set(ax,'YMinorGrid','on')
till here code works same for both versions, but now when i save the figure
saveas(gcf,'fgname','png')
the above saveas command saves the figure with size
- 1200 * 900 pixels --> in 2013b
- 1920 * 1013 pixels --> in 2020b
the size increases in 2020b, is there a way in which i can save the images of size 1200*900 pixels in 2020b version as well retaining the same quality of image.
0 comentarios
Respuesta aceptada
yanqi liu
el 19 de En. de 2022
yes,sir,may be use print or exportfig、getframe+frame2im,such as
print(gcf,'-dpng','-r200','fgname')
0 comentarios
Más respuestas (1)
Richard Quist
el 23 de En. de 2022
Editada: Richard Quist
el 23 de En. de 2022
When calling saveas, the size of the exported image is controlled by the figure's PaperPosition property. Prior to R2016a the default for that property was 8x6 inches; that size will result in the saved image being 1200x900 pixels at the default output resolution of 150 DPI.
In order to get that same output size you can set the figure's PaperPosition width and height; assuming your figure PaperUnits property is set to 'inches' you can add this line after you create your figure:
fh.PaperPosition(3:4) = [8 6];
If your figure PaperUnits property is not set to 'inches' just set the PaperPosition to the equivalent of 8x6 inches in whatever those units are.
0 comentarios
Ver también
Categorías
Más información sobre Printing and Saving en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!