Borrar filtros
Borrar filtros

Interpolation on a 2d grid for a single point

21 visualizaciones (últimos 30 días)
Curtis Lam
Curtis Lam el 4 de Oct. de 2021
Editada: DGM el 4 de Oct. de 2021
I was wondering if there is a way to interpolate a singular point on a 2d meshgrid instead of the grid itself. I already know how to use interp2 for interpolation but was wondering if there was another method.
For clarity, look at the image. I want to use the 4 nodes to interpolate the value at the point in the middle. Is this possible with MATLAB?

Respuestas (2)

Walter Roberson
Walter Roberson el 4 de Oct. de 2021

DGM
DGM el 4 de Oct. de 2021
Editada: DGM el 4 de Oct. de 2021
I suppose if you just want to restrict the process to just the four neighbor points, you could do something like this. I'm sure it can be simpler, but it's faster than using the whole arrays.
[xx yy] = meshgrid(11:2000);
zz = xx+yy;
querypt = [15.5 15.5];
% example using the whole arrays
tic
interp2(xx,yy,zz,querypt(1),querypt(2),'linear')
toc
% just use the four neighbor points instead
tic
sampidxx = [find(xx(1,:) <= querypt(1),1,'last') find(xx(1,:) >= querypt(1),1,'first')];
sampidxy = [find(yy(:,1) <= querypt(2),1,'last') find(yy(:,1) >= querypt(2),1,'first')];
interp2(xx(sampidxx,sampidxy),yy(sampidxx,sampidxy),zz(sampidxx,sampidxy),querypt(1),querypt(2),'linear')
toc
I suppose if you really wanted to not use interp2(), you could do a little bilinear interpolation math of your own based on those four points

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by