how to obtain a slope

122 visualizaciones (últimos 30 días)
shalipse
shalipse el 21 de Nov. de 2016
Comentada: Image Analyst el 21 de Nov. de 2016
Hello All,
Could someone please explain to me how to obtain the slope of each individual line in a plot. I have three plots and would like to draw a straight line to pass through each and compute the slopes (see image attached).
Thank you
Regards
Ismaeel

Respuesta aceptada

Star Strider
Star Strider el 21 de Nov. de 2016
The easiest way would be to use the polyfit function for a 1-order (linear) polynomial:
b = polyfit(x, y, 1);
slope = b(1);
Do the same for each curve in a for loop. (If you want to evaluate the line to plot it, use the polyval function.)
Without knowing how your data are organised (as row or column vectors for example), it is not possible to write specific code for the loop.
  3 comentarios
Star Strider
Star Strider el 21 de Nov. de 2016
My pleasure.
You had originally posted three plots on the same axes with oscillations around what appeared to be a line of constant slope (different for each one), each in a different colour so I assume each from a different source.
You cannot do a regression with only one variable. You need to have at least one x (independent) and at least one y (dependent) variable to do a regression. From your description, you have vectors of dependent or y variables. You would need to choose something for your independent x variable in order to do the regression, although it is up to you to define it. (It could just be the index values of your vector, or it could be time, distance, or whatever it is that you measured to get your data.)
The slope is defined as (change in y-variable)/(change in x-variable) with associated units, so the units of both of your variables are important to correctly interpret your data.
Image Analyst
Image Analyst el 21 de Nov. de 2016
Can you restore those 3 plots? They're not posted anymore.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by