Fill the big gaps in data series
8 次查看(过去 30 天)
显示 更早的评论
Good day!
I have a data series with two big gaps:
For short gaps I usualy used the hermite spline (pchip) or regression (polyfit) but here its not suitable:
Tell me please where can I find a more suitable solution, something like ...
Thanks a lot
采纳的回答
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-')
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)
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');
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 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!