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

조회 수: 3 (최근 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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by