2016-04-15 74 views
0

我想插我的時間序列數據,使其在均勻間隔的時間線,我用下面的代碼插值與多個樣本時間序列數據的同時

% 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]; 
+0

您的'interp1'調用是無效的MATLAB語法。你是否嘗試過'interp1(series(:,1),series(:,2),t,'linear');'? – Suever

回答

0

您收到此錯誤,因爲你明顯地在你的輸入數據的重複次數。您需要以某種方式處理這些重複項。一種做法是,每次只使用重複值的第一個。你可以用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'); 

相反,如果你想在同一時間採樣的所有值被一起平均,可以使用uniqueaccumarray相結合,爲你做這個。

%// 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'); 
+0

謝謝,我試過這個,但仍然是相同的錯誤響應。 – Tina

+0

謝謝,這完全有效! – Tina

相關問題