2014-11-06 67 views
0

我有以下數據集:使用interp1時間序列

27/10/2014,11:45:00,231 
27/10/2014,12:00:00,229 
27/10/2014,12:15:00,NaN 
27/10/2014,12:30:00,NaN 
27/10/2014,12:45:00,227 
27/10/2014,13:00:00,225 
27/10/2014,13:15:00,NaN 
27/10/2014,13:30:00,NaN 
27/10/2014,13:45:00,222 
27/10/2014,14:00:00,221 
27/10/2014,14:15:00,NaN 
27/10/2014,14:30:00,NaN 
27/10/2014,14:45:00,219 
27/10/2014,15:00:00,218 
27/10/2014,15:15:00,NaN 
27/10/2014,15:30:00,NaN 
27/10/2014,15:45:00,214 

我需要使用interp1命令插值丟失的數據:

date_string = strcat (dados.textdata(2:end,2),{' '}, dados.textdata(2:end,3)); 
xdate = datenum (date_string, 'dd/mm/yyyy HH:MM:SS'); 
xi = (1 :length(xdate))'; 
yi = interp1 (xdate,dados.data,xi); 

然而,易建聯只返回NaN的。

如何繪製插值?

+1

從輸入取出的NaN。 – AnonSubmitter85 2014-11-06 20:20:35

回答

3

As @ AnonSubmitter85提到,您首先要從輸入中刪除nan。

r = ~isnan(dados.data); 
yi = interp1(xdate(r),dados.data(r),xi); 

不過,你可能也想用xdate而非xi作爲參數的內插數據:這可以這樣做。

yi = interp1(xdate(r),dados.data(r),xdate); 

輸出然後enter image description here