具有时间序列数据的单元阵列的1-d插值

时间:2016-03-11 08:22:35

标签: arrays matlab cell interpolation

我有一个15174x21的单元阵列,在每列中包含NaN值的时间序列(如下所示)中有各种度量。我是否最适合为每列使用For循环来插值NaN值但保留数组的尺寸?

93.36   93.36   9.3218  23.03   14.0967 22.0596 6.66088 24.3851
93.4    93.4    9.31331 23.0291 14.0115 21.9569 NaN     NaN
93.44   93.44   9.32774 23.0266 14.1254 22.1864 6.6727  24.4036
93.48   93.48   9.32612 23.0336 14.1612 22.1168 6.40944 24.3949
93.52   93.52   9.32374 23.0362 14.0691 22.1711 NaN     NaN
93.56   93.56   9.31864 23.0342 14.1201 22.1799 6.15716 24.2267

由于

1 个答案:

答案 0 :(得分:0)

如果您只是想根据NaN值之前和之后的值进行插值;您可以找到每个NaN值的索引,并根据前进的值和超过该值来更改它。见下面的例子:

[r, c] = find(isnan(cell2mat(TimedEditNumbersWS3)));
for i = 1:length(r)
    if r(i) == 1
        k = 1;
        while isnan(TimedEditNumbersWS3{r(i)+k,c(i)})
            k = k + 1;
        end
        TimedEditNumbersWS3(r(i),c(i)) = TimedEditNumbersWS3(r(i)+k,c(i));
    else
    TimedEditNumbersWS3(r(i),c(i)) = {(TimedEditNumbersWS3{r(i)-1,c(i)} + TimedEditNumbersWS3{r(i)+1,c(i)}) / 2};
    end
end