Reputation: 401
In a project that I am doing I need to reach floating indexed elements of a matrix. That is to say for instance I want to reach the (16.25,1) th element of a matrix. That might seem odd at the first glance. However, by (16.25,1), I mean the interpolation between (16,1) and (17,1) with weights of .25 and .75 respectively.
Is there a built-in function for that?
Many thanks, Safak
Upvotes: 1
Views: 1963
Reputation: 56905
You can use interp2
:
Z = randi(10,10); % 10 x 10 random matrix with integers from 1 to 10
Z(1:2,1:2)
%ans =
% 2 4
% 7 6
% use interp2 to interpolate at row 1.5, col 2
z = interp2(Z,1.5,2)
% z = 6.5000
Upvotes: 2
Reputation:
You can use 2-D interpolation:
ZI = interp2(Z,XI,YI) assumes that X = 1:n and Y = 1:m, where [m,n] = size(Z)
where Z
is your matrix, and XI
& YI
are your fractional indices.
Upvotes: 1