Producing a line of best fit with equation
196 次查看(过去 30 天)
显示 更早的评论
Hi
I have been using lsline to produce a linear line of bext fit for two datasets. I was wondering if there was a similar command that produced the line of best fit and provided an equation (in the form y=mx+c) for said line.
Many Thanks
0 个评论
采纳的回答
Sebastian Castro
2016-4-24
There is also the polyfit function in MATLAB. If you specify an order of 1, the output of polyfit will have the two components m and c as you specified.
- Sebastian
0 个评论
更多回答(2 个)
Kylie Hansen
2017-2-16
编辑:Image Analyst
2021-12-10
Thought I'd share an alternate answer from this github repository:
The code below prints a 1x2 matrix where the first value is the slope of the line and the second is the y-int.
Just plug into slope intercept form (y = mx+ b) and you've got the equation.
h = lsline ;
p2 = polyfit(get(h,'xdata'),get(h,'ydata'),1)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Gaussian Process Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!