saveas commad saves a figure with different size in MATLAB version 2013b and 2020b

18 views (last 30 days)
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;
intScaLeftVal = 1;
intScaWidth = intVecMonitorResolution(1,3);
if intVecMonitorResolution(4) > 200
intScaHeight = intVecMonitorResolution(4)*0.75;
intScaBottomVal =intVecMonitorResolution(4)*0.1;
intScaBottomVal = 1;
intScaHeight = intVecMonitorResolution(1,4);
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;
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
  1. 1200 * 900 pixels --> in 2013b
  2. 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.

Accepted Answer

yanqi liu
yanqi liu on 19 Jan 2022
yes,sir,may be use print or exportfig、getframe+frame2im,such as

More Answers (1)

Richard Quist
Richard Quist on 23 Jan 2022
Edited: Richard Quist on 23 Jan 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.


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




Community Treasure Hunt

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

Start Hunting!