saveas commad saves a figure with different size in MATLAB version 2013b and 2020b
조회 수: 11(최근 30일)
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 = 1;
intScaWidth = intVecMonitorResolution(1,3);
if intVecMonitorResolution(4) > 200
intScaHeight = intVecMonitorResolution(4)*0.75;
intScaBottomVal = 1;
intScaHeight = intVecMonitorResolution(1,4);
monitor_pos = [intScaLeftVal intScaBottomVal intScaWidth intScaHeight];
% monitor_pos =
% 1.0e+03 *
% 0.1536 0.0864 1.2288 0.6480
x = 1:1:5;
y = 1:1:5;
ax=axes('parent',fh,'FontWeight','demi','FontSize',12,'FontName','Times New Roman','LineWidth',2,'TickDir','out');
till here code works same for both versions, but now when i save the figure
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.
Richard Quist 2022년 1월 23일
편집: Richard Quist 2022년 1월 23일
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.