Is there a way to calculate the incremental slope of a graph for each point and then plot (x, slope)?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Adam Danz
am 19 Sep. 2018
Bearbeitet: Adam Danz
am 19 Sep. 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 Kommentare
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!