如何在 MatLab 中使用 TriScatteredInterp?

发布于 2024-12-10 08:41:27 字数 779 浏览 0 评论 0原文

我在 MatLab 中遇到 TriScatteredInterp 问题。 我正在使用一组坐标点以及该位置的相应温度。它们均以度为单位(经度、纬度、温度)。我想对这些点进行插值,这样我就可以找出其他点的值并构建网格。 这就是我到目前为止所做的:

long = data(:,1)
lat = data(:,2)
values = data(:,3)
lat = lat.*(pi/180)
long = long.*(pi/180)
X = cos(lat).*cos(long)
Y = cos(lat).*sin(long)
Z = sin(lat)
F = TriScatteredInterp(X,Y,Z,values)
[long1 lat1] = meshgrid(-pi:pi/360:pi, -pi/2:pi/360:pi/2);
X1 = cos(lat1).*cos(long1)
Y1 = cos(lat1).*sin(long1)
Z1 = sin(lat1);
F.Method = 'natural'
InterpVals = F(X1,Y1,Z1);
mesh(long1, lat1, InterpVals)

正如您所看到的,对于每个(长、纬度)点,我计算了球体上的相应点并使用了 TriScatteredInterp 的 3d 版本。 问题是插值仅适用于“最近”方法,而线性或自然插值仅产生 NaN。正如我所读到的,当我想要插值的点位于三角剖分的凸包之外时,就会发生这种情况,但由于所需的点恰好在球体上,并且输入点覆盖整个范围(长:-180 到180,纬度:-90 到 90),我只是不明白所有的点怎么可能在凸包之外。任何帮助将不胜感激,ty。

I am having a problem with TriScatteredInterp in MatLab.
I am using a set of coordinate points with the corresponding temperature at that location. They are all in degrees in the form (long, lat, temp). I want to make an interpolant on these points so I can find out the values at other points and build a grid.
This is what I have done so far:

long = data(:,1)
lat = data(:,2)
values = data(:,3)
lat = lat.*(pi/180)
long = long.*(pi/180)
X = cos(lat).*cos(long)
Y = cos(lat).*sin(long)
Z = sin(lat)
F = TriScatteredInterp(X,Y,Z,values)
[long1 lat1] = meshgrid(-pi:pi/360:pi, -pi/2:pi/360:pi/2);
X1 = cos(lat1).*cos(long1)
Y1 = cos(lat1).*sin(long1)
Z1 = sin(lat1);
F.Method = 'natural'
InterpVals = F(X1,Y1,Z1);
mesh(long1, lat1, InterpVals)

As you can see for every (long, lat) point, I have computed the corresponding point on the sphere and have used the 3d version of TriScatteredInterp.
The problem is that the interpolation only works for the 'nearest' method, as for the linear or natural is producing just NaN's. As I have read this happens when the points that I want to interpolate are outside of the convex hull of the triangulation, but as the points needed are exactly on the sphere, and the input points are covering the entire range (Long : -180 to 180, Lat : -90 to 90), I just don't see how all the points could be outside the convex hull. Any help will be appreciated , ty.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女的英雄梦 2024-12-17 08:41:27

您应该在二维原始数据(纬度)上插入,而不是在三维数据(X YZ)。
请注意,我为无法访问您的 data() 的读者提供了一些虚拟数据生成器!

n = 100;
long = rand(n,1)*720-360;
lat = rand(n,1)*180-90;
values = rand(n,1)*30-5;
lat = lat.*(pi/180);
long = long.*(pi/180);

F = TriScatteredInterp(long,lat,values);
[long1 lat1] = meshgrid(-pi:pi/36:pi, -pi/2:pi/24:pi/2);
InterpVals = F(long1,lat1);

X1 = cos(lat1).*cos(long1);
Y1 = cos(lat1).*sin(long1);
Z1 = sin(lat1);
mesh(X1,Y1,Z1,InterpVals); %note here the meshing on the regular grid (X1,Y1,Z1)

地图边缘仍然存在问题,因为插值器不知道数据“环绕”。这些边上的 InterpVals 的内容将是.. NaN!

编辑:包装建议:
1) 重写 TriScatteredInterp,使其使用模数;
2)围绕地图的“边缘”镜像数据,进行插值,然后将其裁剪回原始大小;
3) 查看 Matlab 绘图工具箱,它可以分析和可视化地理信息。

You should interpolate values on the bi-dimensional original data (long, lat), not on the tri-dimensional one (X, Y, Z).
Note that I included some dummy data generator, for the readers that do not have access to your data()!

n = 100;
long = rand(n,1)*720-360;
lat = rand(n,1)*180-90;
values = rand(n,1)*30-5;
lat = lat.*(pi/180);
long = long.*(pi/180);

F = TriScatteredInterp(long,lat,values);
[long1 lat1] = meshgrid(-pi:pi/36:pi, -pi/2:pi/24:pi/2);
InterpVals = F(long1,lat1);

X1 = cos(lat1).*cos(long1);
Y1 = cos(lat1).*sin(long1);
Z1 = sin(lat1);
mesh(X1,Y1,Z1,InterpVals); %note here the meshing on the regular grid (X1,Y1,Z1)

There is still an issue on the edges of the map, as the interpolator doesn't know that the data "wraps" around. The content of InterpVals on those edges will be.. NaN!

Edit: suggestions for the wrapping:
1) rewrite TriScatteredInterp so that it uses modulos;
2) mirror the data around the "edges" of the map, interpolate, then crop it back to original size;
3) check out the Matlab Mapping Toolbox, which analyze and visualize geographic information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文