【问题标题】:How do I interpolate this matlab data column containing NaNs?如何插入这个包含 NaN 的 matlab 数据列?
【发布时间】:2014-10-22 21:06:19
【问题描述】:

所以我有一个数据列“trainData”,看起来像:

[
    Nan
    Nan
    Nan
    110
    NaN
    89
    Nan
    Nan
    123

and so on
]

我基本上需要对此进行插值以获得最终的矩阵列:

[
    0
    36.6
    73.2
    110
    99.5
    89
    101.3
    112.6
    123

and so on
]

谁能帮我怎么做?

我尝试做interpl(traindata) 但这要么给我一些奇怪的 NaN 行,要么不起作用。请帮我解决这个问题。

【问题讨论】:

  • 其实这不是插值,因为缺少起点你实际上是在外插。
  • 嗯...在这种情况下,我们可以假设起点为零。

标签: matlab interpolation


【解决方案1】:
y = [NaN
     NaN
     NaN
     110
     NaN
     89
     NaN
     NaN
     123];

以下内容让您非常接近(我认为您实际上犯了算术错误,这就是您想要的):

y(1) = 0; %//I'm assuming this from your result, you gave us no information about this.

xi = (1:length(y))'; %'//Now I'm assuming that each element of your y matrix is equally spaced
x = xi(~isnan(y)); %// Find the x values that correspond to the numerical values of y
yi = interp1(x, y(~isnan(y)), xi)

yi =

         0
   36.6667
   73.3333
  110.0000
   99.5000
   89.0000
  100.3333
  111.6667
  123.0000

【讨论】:

    猜你喜欢
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 2013-12-17
    • 1970-01-01
    相关资源
    最近更新 更多