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 visualizaciones (últimos 30 días)
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.

Respuestas (1)

Walter Roberson
Walter Roberson el 20 de Oct. de 2023
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

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by