Producing a line of best fit with equation
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (2)
Image Analyst
il 24 Apr 2016
1 voto
See attached demo of polyfit.
Kylie Hansen
il 16 Feb 2017
Modificato: Image Analyst
il 10 Dic 2021
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)
2 Commenti
Ryan Kunen
il 10 Dic 2021
h = lsline ;
p2 = polyfit(get(h,'xdata'),get(h,'ydata'),1)
Image Analyst
il 10 Dic 2021
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!