how to get the equation of lsline
46 次查看(过去 30 天)
显示 更早的评论
hi. I have two set of data and I want to get the linear regression. after plotting the data, im using lsline to obtain the regression line but how can I get the equation too ? thanks !
0 个评论
采纳的回答
Star Strider
2017-2-11
You have to calculate it, but that is not difficult.
Example:
figure(1)
scatter(1:10, rand(1, 10))
hl = lsline;
B = [ones(size(hl.XData(:))), hl.XData(:)]\hl.YData(:);
Slope = B(2)
Intercept = B(1)
更多回答(1 个)
Kylie Hansen
2017-2-16
Thought I'd post an alternative answer from this github repository: https://github.com/kykyelric/Marking-Points-Above-Line-of-Best-Fit/blob/master/lsline%20equation
The below code prints a 1x2 matrix where the first value is the slope and the second is the y-int.
h = lsline;
p2 = polyfit(get(h,'xdata'),get(h,'ydata'),1)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!