how to get the equation of lsline

조회 수: 61 (최근 30일)
farfar
farfar 2017년 2월 11일
답변: Kylie Hansen 2017년 2월 16일
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 !

채택된 답변

Star Strider
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)
  댓글 수: 2
farfar
farfar 2017년 2월 11일
Thanks!
Star Strider
Star Strider 2017년 2월 11일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Kylie Hansen
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)

카테고리

Help CenterFile Exchange에서 Regression에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by