2

This is probably a very easy question, but all the sources I have found on interpolation in Matlab are trying to correlate two values, all I wanted to benefit from is if I have data which is collected over an 8 hour period, but the time between data points is varying, how do I adjust it such that the time periods are equal and the data remains consistent?

Or to rephrase from the approach I have been trying: I have GPS lat,lon and Unix time for these points; what I want to do is take the lat and lon at time 1 and time 3 and for the case where I don't know time 2, simply fill it with data from time 1 - is there a functional way to do this? (I know in something like Python Pandas you can use fill) but I'm unsure of how to do this in Matlab.

4

5 回答 5

2

您可以查看 MATLAB 中的拟合方法。例如,您可以查看polyfitsplines。我们来看看polyfit,它的使用方法是:

P = polyfit(X,Y,N);

这里 X 是您的时间数据,Y 是您在 X 中的时间值测量的 GPS 数据。N 是多项式的阶数。当您计算 P 时,您可以将polyval函数用作:

Y1 = polyval(P,X1);

这里 X1 是统一的时间样本,例如 X1=[1 2 3 4 5 6 7 8] 在您的情况下,Y1 将是那些时间的估计数据, P 是您使用polyfit.

于 2013-02-07T06:44:46.640 回答
2

你可以做的是使用 interp1 函数。此功能将以不同的方式适合新 X 系列的数字。例如,如果您有 x=[1 3 5 6 10 12] y=[15 20 17 33 56 89]

这意味着如果您想填写 x1=[1 2 3 4 5 6 7 ... 12],您将输入 y1=interp1(x,y,x1)

于 2013-02-07T15:16:31.990 回答
2

您可以尝试以下方法:

 resampledTime = min(unixTime):resampleInterval:max(unixTime);
 resampledLat = interp1(time,lat,resampledTime);
 resampledLon = interp1(time,lon,resampledTime);

默认情况下,这将返回一维线性插值。有关详细信息,请参阅help interp1

于 2013-02-09T01:11:28.400 回答
2

有一个名为interparc.m的 MATLAB 函数将使您受益。它通过点拟合三次样条,并将生成的线分成相等的弧长(取决于用户输入的点数)

于 2013-03-11T23:00:48.867 回答
1

我认为您正在寻找“零阶保持”插值,即“最近邻”

你为什么不试试interp方法'nearest'

于 2013-02-07T15:18:08.357 回答