MATLAB: Resize an Image while preserving aspect ratio in MATLAB Report Generator R2018a

generatorheightimageMATLABMATLAB Report Generatorreportresizewidth

I would like to resize my image in MATLAB Report Generator but preserve the aspect ratio. I am using the method described in the link below, but I have not found an easy way to preserve the aspect ratio.

Best Answer

See the example which shows how if you only specify the "Height" in the "<image>.Style" property and not the "Width", then the aspect ratio is preserved.
import mlreportgen.dom.*
%create document
d = Document('imageArea2','pdf');
%create two images, origional and resized
img_orig = Image('circle.png');
img_resize = Image('circle.png');
%resize one image
img_resize.Style = {Height('2.5in')}; %the new height we want in inches
%add both to document and view
append(d,img_orig);
append(d,img_resize);
close(d);
rptview(d.OutputPath);