在 matlab 中插值不规则间隔的 3D 矩阵

发布于 2025-01-08 19:07:43 字数 414 浏览 3 评论 0原文

我有一个温度曲线的时间序列,我想对其进行插值,我想问如果我的数据间隔不规则,该怎么做。

以下是矩阵的具体情况:

  • 温度为 30x365
  • 时间为 1x365
  • 深度为 30x1

时间和深度都是不规则间隔的。我想问一下如何将它们插入到常规网格中?

我在 Matlab 中查看了 interp2TriScatteredInterp,但问题如下:

  1. interp2 仅当数据位于常规网格中时才有效。
  2. TriscatteredInterp 仅当向量是列向量时才起作用。虽然时间和深度都是列向量,但温度不是。

谢谢。

I have a time series of temperature profiles that I want to interpolate, I want to ask how to do this if my data is irregularly spaced.

Here are the specifics of the matrix:

  • The temperature is 30x365
  • The time is 1x365
  • Depth is 30x1

Both time and depth are irregularly spaced. I want to ask how I can interpolate them into a regular grid?

I have looked at interp2 and TriScatteredInterp in Matlab, however the problem are the following:

  1. interp2 works only if data is in a regular grid.
  2. TriscatteredInterp works only if the vectors are column vectors. Although time and depth are both column vectors, temperature is not.

Thanks.

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

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

发布评论

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

评论(3

与他有关 2025-01-15 19:07:43

函数 Interp2 根本不需要规则间隔的测量网格,它只需要单调网格。也就是说,存储在向量深度中的采样位置必须增加(或减少),仅此而已。

假设这确实是情况*并且您想要在存储在向量rdepthsrtimes<中的常规位置**进行插值/code>,你可以这样做:

[JT, JD] = meshgrid(times, depths); %% The irregular measurement grid
[RT, RD] = meshgrid(rtimes, rdepths); %% The regular interpolation grid
TemperaturesOnRegularGrid = interp2(JT, JD, TemperaturesOnIrregularGrid, RT, RD);

* :如果没有,您可以对行和列进行排序以返回单调网格。
*
*:事实上Interp2对输出网格没有限制(它可以是不规则的,甚至是非单调的)。

Function Interp2 does not require for a regularly spaced measurement grid at all, it only requires a monotonic one. That is, sampling positions stored in vectors depths and times must increase (or decrease) and that's all.

Assuming this is indeed is the situation* and that you want to interpolate at regular positions** stored in vectors rdepths and rtimes, you can do:

[JT, JD] = meshgrid(times, depths); %% The irregular measurement grid
[RT, RD] = meshgrid(rtimes, rdepths); %% The regular interpolation grid
TemperaturesOnRegularGrid = interp2(JT, JD, TemperaturesOnIrregularGrid, RT, RD);

* : If not, you can sort on rows and columns to come back to a monotonic grid.
*
*: In fact Interp2 has no restriction for output grid (it can be irregular or even non-monotonic).

我要还你自由 2025-01-15 19:07:43

我会使用您的数据来拟合样条曲线或多项式,然后定期重新采样。我强烈推荐 polyfitn 函数。事实上,约翰·德埃里科这个家伙的任何作品都令人难以置信。除此之外,当我有关于不规则间隔的 3D 问题的数据时,我过去曾使用过此函数,并且效果相当不错。如果你的数据集有很好的支持(我怀疑确实如此),那么这将是小菜一碟。享受!希望这有帮助!

I would use your data to fit to a spline or polynomial and then re-sample at regular intervals. I would highly recommend the polyfitn function. Actually, anything by this John D'Errico guy is incredible. Aside from that, I have used this function in the past when I had data on a irregularly spaced 3D problem and it worked reasonably well. If your data set has good support, which I suspect it does, this will be a piece of cake. Enjoy! Hope this helps!

固执像三岁 2025-01-15 19:07:43

尝试使用 MATLAB Central 上 John D'Errico 提供的 GridFit 工具。要使用它,请传入 2 个独立的数据向量(时间和温度)、相关数据矩阵(深度)以及规则间隔的 X 和温度。要使用的 Y 数据点。默认情况下,该工具还会对重叠(或接近)的数据点进行平滑处理。如果不需要,您可以通过各种配置选项覆盖此选项(和其他选项)。示例代码:

%Establish regularly spaced points
num_points = 20;
time_pts = linspace(min(time),max(time),num_points);
depth_pts = linspace(min(depth),max(depth),num_points);

%Run interpolation (with smoothing)
Pest = gridfit(depth, time, temp, time_pts, depth_pts);

Try the GridFit tool on MATLAB central by John D'Errico. To use it, pass in your 2 independent data vectors (time & temperature), the dependent data matrix (depth) along with the regularly spaced X & Y data points to use. By default the tool also does smoothing for overlapping (or nearly) data points. If this is not desired, you can override this (and other options) through a wide range of configuration options. Example code:

%Establish regularly spaced points
num_points = 20;
time_pts = linspace(min(time),max(time),num_points);
depth_pts = linspace(min(depth),max(depth),num_points);

%Run interpolation (with smoothing)
Pest = gridfit(depth, time, temp, time_pts, depth_pts);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文