How can I draw the slope of the given values ​​on the chart?

254 views (last 30 days)
x=[0.5, 1.0, 1.10, 1.20, 1.30, 1.40, 1.50, 2.0, 2.5, 3.0, 3.5, 4.0, 4.10, 4.20, 4.30, 4.40, 4.5, 5 ];
y=[4.91, 4.91, 4.9190, 4.9187, 4.9165, 4.9099, 4.89, 4.58, 3.86, 2.85, 1.65, 1.06, 1.0153, 0.9751, 0.9422, 0.9072, 0.87, 0.77];
plot (x,y);
hold on;
slope=(diff(y)./diff(x));
for the given values how can ı draw and calculate slope on the graph.

Accepted Answer

Star Strider
Star Strider on 13 Mar 2019
I would use the gradient function rather than diff for this, since gradient produces a numerical derivative the same size as the argument:
slope = (gradient(y)./gradient(x));
plot (x,y);
hold on
plot(x, slope)
hold off
Experiment to get the result you want.
  4 Comments
Star Strider
Star Strider on 13 Mar 2019
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

More Answers (0)

Categories

Find more on Two y-axis in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!