Linear interpolation of a 2d array to another 2d array

2 次查看(过去 30 天)
Hi,
How can I linearly interpolate a rectangular 2d array (50 by 36) into a another rectagular array say (25 by 18). I know MATLAB's interp1 function can do this but unfortunately it returns "Nan" in some of the output array elements. How can I circumvent this issue ?
  2 个评论
thoughtGarden
thoughtGarden 2019-9-20
Can you give an example of what you want, say with a 2X2 and 1X2 2d array? interpolation across arrays of different sizes doesn't make much sense (and I'm not sure interp1 can do what you are looking for).
for example:
arr1 = [2,4;5,6];
arr2 = [1,3];
val = yourFunc(arr1,arr2,1.5)
what do you expect val should be?
Walter Roberson
Walter Roberson 2019-9-20
imresize() ? Or take the mean or median of each 2 x 2 block perhaps?

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2019-9-21
You are getting NaN's because some of the query locations where you have asked interpolation to be performed are outside the boundaries of the array.
However, as the others have said, interpolation is a peculiar way to downsample an array. More typically, you would do 2x2 binning. If that is what you actually want, you could use this FEX file,
For example
>> A=rand(50,36);
>> B = sepblockfun(A,[2,2],'mean');
>> whos A B
Name Size Bytes Class Attributes
A 50x36 14400 double
B 25x18 3600 double

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by