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.

3 ビュー (過去 30 日間)
raym
raym 2023 年 10 月 20 日
回答済み: Walter Roberson 2023 年 10 月 20 日
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 Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by