get(gca,'D​ataAspectR​atio') does not refelct the real pixel ratio, and does not upate after stretching the figure window in default auto mode.

조회 수: 2 (최근 30일)
Hi, I am using imagesc to show a matrix and want to get the aspect ratio of pixels at that time:
C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
imagesc(C)
a = get(gca,'DataAspectRatio') % [2.0000 1.5000 1.0000] looks not close enough to real display.
aMode = get(gca,'DataAspectRatiomode') %auto
% however, after set the aspect ratio to its original value, the display changed:
set(gca,'DataAspectRatio',a)
% The initial aspect ratio value [2.0000 1.5000 1.0000] is more close to the 2nd image.
C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
imagesc(C)
a = get(gca,'DataAspectRatio') % [2.0000 1.5000 1.0000]
aMode = get(gca,'DataAspectRatiomode') %auto
% I stretch the window, then retrieve the ratio again, but it still the same
a = get(gca,'DataAspectRatio') % [2.0000 1.5000 1.0000]
Why the initial retrieved aspect ratio does not reflect the displayed image and it does not update?
Thanks.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 10월 20일
set(gca,'DataAspectRatio',a)
when you set the DataAspectRatio then DataAspectRatioMode is set to 'manual' -- but the mode must be 'auto' in order for stretch-to-fill behaviour to be active. This is pointed out clearly in daspect

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by