How to create a smooth curve through data points?
Ältere Kommentare anzeigen
I have a basic plot as follows. x = [0 0.2 0.4 0.8 1.2 1.6 2.0]; y = [0 0.155 0.240 0.328 0.450 0.582 0.692];
plot(x,y,'x','MarkerEdgeColor','black') grid on; xlabel('Protein standard concentration (µg/µl)'); ylabel('Average absorbance value');
Now I want a smooth curve to go through the data points. Any suggestions?
Akzeptierte Antwort
Weitere Antworten (2)
John D'Errico
am 5 Dez. 2017
The question is, do you have knowledge of this process? Well, everybody knows something about their data, about the underlying system that produced it.
For example, do you know the curve passes through (0,0)? Very often, when point is supplied as (0,0), you know the curve passes through that point.
Is the bump down at the bottom real, or is it just noise?
Thus, the smoothest curve I can imagine is this:
S = x(:)\y(:)
S =
0.36704
plot(x,y,'o',x,S*x,'r-')

What I don't know is if the lack of fit is significant, or just data noise.
Of course, if the point at zero is not important, then a simple linear fit with a constant makes sense.
P1 = polyfit(x,y,1); plot(x,y,'o',x,P1(1)*x+P1(2),'r-')

Alternatively, we might consider a cubic polynomial, with no constant term.
C = (x(:).^(1:4))\y(:);
xint = linspace(0,2,100)';
plot(x,y,'o',xint,(xint.^(1:4))*C,'r-')

Thus,
y = C(1)*x + C(2)*x^2 + C(3)*x^3 + C(4)*x^4
That forces the curve to pass through zero, has a bump at the bottom end, etc. But it has a little tweak near the top.
spl = spline(x,y);
plot(x,y,'o',xint,ppval(spl,xint),'r-')

What matters is what you know about the curve, what you know about the data.
1 Kommentar
Inteeskimo
am 6 Dez. 2017
MHZ
am 5 Dez. 2017
1 Stimme
One option is cftool Another option is polyfit function Third option is smooth function
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!