Effacer les filtres
Effacer les filtres

Interpolation on a 2d grid for a single point

21 vues (au cours des 30 derniers jours)
Curtis Lam
Curtis Lam le 4 Oct 2021
Modifié(e) : DGM le 4 Oct 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?

Réponses (2)

Walter Roberson
Walter Roberson le 4 Oct 2021

DGM
DGM le 4 Oct 2021
Modifié(e) : DGM le 4 Oct 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

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by