how to fit a curve in matlab?
9 views (last 30 days)
Show older comments
i have a curve like shown and i need to make more smmoth -- can you tell the way for doing that if it is possible?

0 Comments
Answers (2)
Cris LaPierre
on 17 Jun 2023
Smoothing and curve fitting are different things.
For smoothing, consider using the Smooth Data live task in a live script to interactively adjust the settings.
For curve fitting, consider the options presented here: https://www.mathworks.com/help/matlab/data_analysis/interactive-fitting.html
0 Comments
John D'Errico
on 17 Jun 2023
Edited: John D'Errico
on 17 Jun 2023
You really have very little signal, compared to what is apprently noise in those "curves". As such, you would be ill-advised to even try to perform any sophisticated smoothing OR curve fitting. At most, you might decide to model/fit them using a linear or at most a quadratic polynomial. Given as few data points as you have, smoothing will also be difficult to do at all well.
And, since you don't actually provide any data, it is even more difficult to help you. But, for example, suppose you had this data.
x = linspace(0,1,8)';
y = cos(x - 2) + randn(size(x))/3;
plot(x,y,'o')
While there may be some information content in that data, I doubt it. At most, you might dcide a straight line is all it is worth. The problem is, too often we end up overfitting our data.
Polyfit can find the coefficients of a straight line fit. Or, we could use fit. Fit is nice, if you have the curve fitting toolbox.
mdl = fit(x,y,'poly1')
plot(mdl,x,y,'o')
mdl2 = fit(x,y,'smoothingspline')
hold on
plot(mdl2,'g')
And you should see that the fit from a smoothing spline is meaningless garbage, the result of throwing a sophisticated tool at data that lacks any redemptive value. With some understanding of a smoothing spline, we COULD arguably make it do better, but the result here would not be much more than just using a simple low order polynomial model.
Simple things are often the best choices.
0 Comments
See Also
Categories
Find more on Smoothing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
