Help : Interpolation missing data
21 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am a beginner in Matlab and I tried to interpolate with a polinomial of 3 order a matrix that has a lot of NaN. I tried with the function 'interp1' using cubic but it didn t work.
CS is my matrix (2880,4) I need to interpolate the 2nd 3rd and 4th column. In the first column there is the time sampling. The vector u,v,w have the NaN in the same position. When I have more than one NaN consecutevely (i.e [1 0.1 NaN NaN NaN NaN NaN]) the interpolation computes a wrong data. I tried using different ways (i.e. inpaint_nans and the results are not good).
Could you suggest me something? I am struggling since 3 days with this problems.
(more info: The CS represent a matrix of velocity measurements filtered using a tool that removed the data with bad correlation and signal to noise, unfortunately this program not replace the spike). I attach the data, so you can have a look.
load CS_7_07.txt
u = CS(:,2); v = CS(:,3); w = CS(:,4);
nanx(:,1) = CS(:,1); nanx = isnan(CS(:,2)); t = 1:numel(CS(:,2));
u(nanx) = interp1(t(~nanx), u(~nanx), t(nanx),'linear', 'extrap'); v(nanx) = interp1(t(~nanx), v(~nanx), t(nanx),'linear', 'extrap'); w(nanx) = interp1(t(~nanx), w(~nanx), t(nanx),'linear', 'extrap');
CS = [CS(:,1) u v w];
0 个评论
回答(3 个)
wil
2015-3-23
You also overwrite nanx in the line
nanx(:,1) = CS(:,1); nanx = isnan(CS(:,2));
Should this be:
nanu = isnan(CS(:,2));
nanv = isnan(CS(:,3));
nanw = isnan(CS(:,4));
You can also try using the following. The values you are giving it to interpolate onto (t(nanx)) does not contain the full list of values you want to interpolate. If you give it all of t, the values for v(~nanx) will remain the same, and it will interpolate the values in between.
u_n = interp1(t(~nanu), u(~nanu), t,'linear', 'extrap');
v_n = interp1(t(~nanv), v(~nanv), t,'linear', 'extrap');
w_n = interp1(t(~nanw), w(~nanw), t,'linear', 'extrap');
CS(:,2:4) = [u_n v_n w_n];
Hope this helps, Wil
0 个评论
Giu Ann
2015-3-23
1 个评论
wil
2015-3-24
If you are trying to extrapolate 71 values from only 3 numeric values, you will find that your extrpolation is very low quality. The extrapolation here is linear, so it will look at the rate of change between the previous values and extrapolate that. Multiply this change by 71 and you have a high number at the end!
John D'Errico
2015-3-23
编辑:John D'Errico
2015-3-23
You need to download it, but it will do the trick with no options needed, replacing ALL NaN elements with interpolated values. Those that must be extrapolated will be extrapolated linearly, really the only safe way to do so.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!