Is there a way to calculate the incremental slope of a graph for each point and then plot (x, slope)?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have made a graph from an array of y and x. I now want to calculate the slope between x1, x2, and x2, x3, and so on. Then I want to plot this slope against the x-values.
How would I go about doing this?
0 comentarios
Respuestas (1)
Adam Danz
el 19 de Sept. de 2018
Editada: Adam Danz
el 19 de Sept. de 2018
The equation for slope is change in y divided by change in x.
slope = (y2 - y1) / (x2 - x1);
Assuming X and Y are vectors of equal length, you can calculate the slope between each neighboring coordinates at once.
slope = (y(2:end) - y(1:end-1)) / (x(2:end) - x(1:end-1));
If the length of X and Y is ' n', then slope will have length ' n-1'.
Then I want to plot this slope against the x-values.
plot(slope, x(2:end))
0 comentarios
Ver también
Categorías
Más información sobre 2-D and 3-D Plots 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!