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

5 ビュー (過去 30 日間)
Ehiremen Ebewele
Ehiremen Ebewele 2019 年 9 月 20 日
回答済み: Matt J 2019 年 9 月 21 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by