Interpolation on a 2d grid for a single point
21 次查看(过去 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!