1

So I have a data column "trainData" that looks like:

[
    Nan
    Nan
    Nan
    110
    NaN
    89
    Nan
    Nan
    123

and so on
]

I basically need to interpolate this so as to get a final matrix column as :

[
    0
    36.6
    73.2
    110
    99.5
    89
    101.3
    112.6
    123

and so on
]

Can anyone help me how to do so?

I tried doing interpl(traindata) but that either gives me some weird row of NaN's or doesn't work. Please help me out with this.

4

1 回答 1

6
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
于 2013-09-25T12:31:22.173 回答