【问题标题】:Interpolation of time series data with multiple samples at the same time同时用多个样本对时间序列数据进行插值
【发布时间】:2016-04-16 03:32:20
【问题描述】:

我正在尝试插入我的时间序列数据,使其位于均匀间隔的时间线上,并且我正在使用以下代码

% interpolate the series
t = 0 : 3 : 400;  
Series 1 = interp1(series 1(:,1),series 1(:,2),t,'linear');

但此错误消息不断出现,我不确定为什么

使用 griddedInterpolant 时出错
网格向量不是严格单调递增的。

interp1 中的错误(第 183 行)
F = griddedInterpolant(X,V,method);

这就是时间序列的一部分

series = [  3.585,  0.21
            5.135,  0.08    
            7.4,    0.19
            11.125, -0.15
            13.175, -0.27
            16.045, -0.26   
            20.37,  -0.12
            25.24,  0.02
            27.58,  0.05
            30.38,  0.02
            33.515  0.1];

【问题讨论】:

  • 您的 interp1 调用不是有效的 MATLAB 语法。你试过interp1(series(:,1), series(:,2), t ,'linear');吗?

标签: matlab linear-interpolation


【解决方案1】:

您收到此错误是因为您的输入数据中显然有重复的时间。您将需要以某种方式处理这些重复项。一种方法是每次只使用重复值的 first。您可以使用unique 轻松做到这一点。

[uniqueTimes, ind] = unique(series(:,1));
vals = series(ind, 2);

%// Values at which we want to interpolate
tt = linspace(min(uniqueTimes), max(uniqueTimes), 100);

%// Perform interpolation
newval = interp1(uniqueTimes, vals, tt, 'linear');

如果您希望将同一采样时间的所有值一起平均,您可以使用unique 结合accumarray 为您执行此操作。

%// Average all values that have the same time
[uniqueTimes, ~, inds] = unique(series(:,1));
vals = accumarray(inds, series(:,2), [], @mean);

%// Values at which we want to inteprolate
tt = linspace(min(uniqueTimes), max(uniqueTimes), 100);

%// Perform interpolation
newval = interp1(uniqueTimes, vals, tt, 'linear');

【讨论】:

  • 谢谢,我试过了,但还是一样的错误响应。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-04-04
  • 1970-01-01
  • 2012-11-06
  • 1970-01-01
  • 2020-10-19
  • 2016-07-01
  • 2019-01-19
相关资源
最近更新 更多