Is there a way to calculate the incremental slope of a graph for each point and then plot (x, slope)?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Adam Danz
il 19 Set 2018
Modificato: Adam Danz
il 19 Set 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 Commenti
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!