MATLAB scatter plot linear regression line

I am trying to get leftovers for a scatter plot of two variables. I could get a linear least squares regression line using the lsline function from matlab. However, I also want to get leftovers. How can I get this in matlab. To do this, I need to know the parameters a and b the linear regression line

 ax+b 
+6
source share
2 answers

Use the polyfit function to get the regression parameters. Then you can evaluate the set values ​​and calculate your residues accordingly.

Basically, a polyfit performs least squares regression for a given degree N, which in your case will be 1 for a straight line regression. The regression parameters are returned by the function, and you can use another polyval function to get the set values ​​from the regression parameters

+7
source

If you have a curve fitting tool , type cftool and press enter and a GUI will appear.

You can use this tool to search for linear polynomial matching for a given dataset, as well as for many other options.

+2
source

Source: https://habr.com/ru/post/919044/


All Articles