- Smooth noisy data using smoothdata https://www.mathworks.com/help/matlab/ref/smoothdata.html
- Fit using ‘polyfit’ https://www.mathworks.com/help/matlab/ref/polyfit.html
- Use cftool for flexible interface where you can interactively fit curves and surfaces to data and view plots. (Requires Curve Fitting Toolbox) https://www.mathworks.com/help/curvefit/curvefitter-app.html. You can also specify your own custom equation to fit your data.
How to create a smooth curve through data points?
조회 수: 656 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
Star Strider
2017년 12월 5일
편집: MathWorks Support Team
2023년 3월 6일
There are various ways you can achieve this:
Below is an example of using 'polyfit'. A linear fit is probably appropriate, unless you have a specific equation you want to fit to it:
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];
p = polyfit(x, y, 1);
v = polyval(p, x);
figure(1)
plot(x,y,'x','MarkerEdgeColor','black')
hold on
plot(x, v)
hold off
grid on;
xlabel('Protein standard concentration (µg/µl)');
댓글 수: 0
추가 답변 (2개)
John D'Errico
2017년 12월 5일
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-')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179813/image.jpeg)
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-')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179815/image.jpeg)
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-')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179817/image.jpeg)
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-')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179818/image.jpeg)
What matters is what you know about the curve, what you know about the data.
MHZ
2017년 12월 5일
One option is cftool Another option is polyfit function Third option is smooth function
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!