Interpolation on a 2d grid for a single point
31 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (2 件)
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
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!