gra*_*aci 1 matlab interpolation
所以我有一个数据列" trainData",看起来像:
[
Nan
Nan
Nan
110
NaN
89
Nan
Nan
123
and so on
]
Run Code Online (Sandbox Code Playgroud)
我基本上需要对此进行插值以获得最终矩阵列:
[
0
36.6
73.2
110
99.5
89
101.3
112.6
123
and so on
]
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我怎么做?
我尝试过,interpl(traindata)但要么给我一些奇怪的NaN或者不行.这个你能帮我吗.
y = [NaN
NaN
NaN
110
NaN
89
NaN
NaN
123];
Run Code Online (Sandbox Code Playgroud)
以下内容让你非常接近(我认为你实际上是一个算术错误,这就是你想要的):
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
Run Code Online (Sandbox Code Playgroud)