Help with basic fitting

1 visualización (últimos 30 días)
aurc89
aurc89 el 23 de Feb. de 2014
Comentada: Image Analyst el 25 de Sept. de 2018
Hello,I would like to fit a curve with a line and retrieve slope and intercept of this linear fit. Let x and y be the vectors which define the curve, which is already similar to a line; I plot x vs y, then from the plot window I select Tools --> Basic fitting --> Linear fit, then I press 'Show equation' so that from the expression y=mx + q I retrieve both the slope m and the intercept q. The problem is that I want to obtain immediatly m and q from the Matlab code, without doing it manually as discussed above. How can I do this ? Thanks

Respuesta aceptada

Mischa Kim
Mischa Kim el 23 de Feb. de 2014
Editada: Mischa Kim el 23 de Feb. de 2014
Try
[p,S] = polyfit(x,y,1)
The two elements of p are the coefficients m and q you are looking for.
  2 comentarios
Andrea Gómez Montoya
Andrea Gómez Montoya el 25 de Sept. de 2018
What is S on the answer?
Image Analyst
Image Analyst el 25 de Sept. de 2018
It's explained in the help for polyfit().

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 23 de Feb. de 2014
for what it's worth, I've attached a demo of polyfit.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by