Is there a way to calculate the incremental slope of a graph for each point and then plot (x, slope)?

6 ビュー (過去 30 日間)
Ken Mathai
Ken Mathai 2018 年 9 月 19 日
編集済み: Adam Danz 2018 年 9 月 19 日
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?

回答 (1 件)

Adam Danz
Adam Danz 2018 年 9 月 19 日
編集済み: Adam Danz 2018 年 9 月 19 日
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))

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by