Fill the big gaps in data series
12 ビュー (過去 30 日間)
古いコメントを表示
Good day!
I have a data series with two big gaps:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1454197/image.jpeg)
For short gaps I usualy used the hermite spline (pchip) or regression (polyfit) but here its not suitable:![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1454202/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1454202/image.jpeg)
Tell me please where can I find a more suitable solution, something like ...
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1454207/image.jpeg)
Thanks a lot
3 件のコメント
採用された回答
John D'Errico
2023 年 8 月 9 日
編集済み: John D'Errico
2023 年 8 月 9 日
The big probem is, your series has little information content in it. :( And of course, you don't give us any data. So I'll make some up. And since I'll be using a few of my own tools that live on the FEX, I'll do it offline.
x = (0:500)';
y = sin(x/300) + randn(size(x))/20;
holes = [200:300,400:450];
unholes = setdiff(1:500,holes);
plot(x(unholes),y(unholes),'b-')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1454277/image.jpeg)
Now, the problem is, if I just connect the first and last points that surround each hole, we get an unwanted effect, in that if those points were high or low, we will get a strange looking curve. It looks instead as if you want a curve that passes through the middle of that noise cloud, following the general trend. That means you need some sort of curve fit, not just an interpolant that looks at the points bounding the holes.
For example, I might have just suggested you use my inpaint_nans tool from the FEX, using the springs option. And it would give you basically that result. You would be unhappy.
Perhas better might be a smoothing spline.
mdl = fit(xuh,yuh,'smoothingspline','smooth',0.0001);
plot(mdl,xuh,yuh)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1454282/image.jpeg)
And that is not at all terrible, but it did depend on my semi-intelligent choice of a smoothing parameter. We could use that function to now fill in the holes, with no problem though.
Another option is my own SLM toolbox. It lives on the File Exchange for free download.
mdl = slmengine(xuh,yuh,'knots',5,'plot','on');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1454287/image.jpeg)
Again, a reasonable curve that will fill in the holes. It needs little in the way of information provided, really only a number of knots to use. Since this is a simple curve, 5 will be entirely reasonable. You really don't care where they fall.
Find SLM here:
Which is better for your specific probem? Probably either could work well enough. There is a strange tweak in your curve at the top end, so I might start with the smoothing spline.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Splines についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!