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

6 次查看(过去 30 天)
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