How do I perform a linear least squares fit
293 次查看(过去 30 天)
显示 更早的评论
Hello.
I would like to perform a linear least squares fit to 3 data points.
The help files are very confusing, to the point where i can't figure out whether this is a base function of Matlab, I need the curve fitting toolbox, optimization toolbox, or both.
Thanks,
Alex
0 个评论
采纳的回答
更多回答(2 个)
Image Analyst
2018-12-21
编辑:Image Analyst
2018-12-21
See attached polyfit demo. Adapt as needed. All you need is base MATLAB - no toolboxes.
For example
coefficients = polyfit(x, y, 1);
yFitted = polyval(coefficients, x); % yFitted will be at the 3 points where x is. There will be 3 yFitted values.
If you want a lot more points, you can pass in more x to polyval():
xFit = linspace(min(x), max(x), 1000); % 1000 points.
yFitted = polyval(coefficients, xFit);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!