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

3 visualizaciones (últimos 30 días)
Ehiremen Ebewele
Ehiremen Ebewele el 20 de Sept. de 2019
Respondida: Matt J el 21 de Sept. de 2019
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 comentarios
thoughtGarden
thoughtGarden el 20 de Sept. de 2019
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 el 20 de Sept. de 2019
imresize() ? Or take the mean or median of each 2 x 2 block perhaps?

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 21 de Sept. de 2019
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

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by