Is there a way to calculate the incremental slope of a graph for each point and then plot (x, slope)?
6 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Adam Danz
on 19 Sep 2018
Edited: Adam Danz
on 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 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!