- 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?
655 ビュー (過去 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!