Interpolation on a 2d grid for a single point

31 ビュー (過去 30 日間)
Curtis Lam
Curtis Lam 2021 年 10 月 4 日
編集済み: DGM 2021 年 10 月 4 日
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?

回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 10 月 4 日

DGM
DGM 2021 年 10 月 4 日
編集済み: DGM 2021 年 10 月 4 日
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

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by