how is it possible to correspond negative coordinates to matrix indices?

조회 수: 1 (최근 30일)
Babak
Babak 2023년 4월 23일
댓글: Babak 2023년 4월 23일
I was working on a piece of code which take a cartesian image and change it to polar demonstration (rho , phi).
using "interp2" negative non-integer numbers correspond to indices of an image (which are positive integers).
in part of the code we see:
x = Pixel_spacing* (-(nrad-0.5):(nrad-0.5));
[x,y] = meshgrid(x,x);
polar_image = interp2(x, y, double(image), xi, yi);
here x and y are expanded on something like (-9.5 , 9.5) and through this these negative coordinates work as indices of matrix. note that x ,y and image are the same size.
having this example in mind, how can correspond indices of a matrix to negative and non-integer contents of another matrix, like the function 'interp2' does?
thanks

답변 (1개)

chicken vector
chicken vector 2023년 4월 23일
You can normalise the coordiante to transorm them into indeces:
x = -9.5 : 9.5; % -9.5 -8.5 ... 8.5 9.5
xIdx = x - x(1) + 1; % 1 2 ... 19 20

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by