# How do I take the derivative of my plot?

686 views (last 30 days)

Show older comments

Alejandro
on 19 Apr 2013

##### 0 Comments

### Accepted Answer

Azzi Abdelmalek
on 19 Apr 2013

dy=diff(y)./diff(x)

plot(x(2:end),dy)

##### 8 Comments

Torsten
on 23 Jan 2023 at 21:31

Edited: Torsten
on 23 Jan 2023 at 21:36

If you only have discrete values for x and y, there is no method to tell you whether there is a discontinuity in the derivative of y in a point x_i.

You can compare (y(i+1)-y(i))/(x(i+1)-x(i)) with (y(i)-y(i-1))/(x(i)-x(i-1)), but even if both differ significantly, it's not possible to decide whether there is a discontinuity in the derivative at x=x(i).

### More Answers (1)

Shaun VanWeelden
on 19 Apr 2013

Call polyfit to generate your polynomial (if you don't already have a polynomial)

Call polyder to get derivative of your fitted line

Call polyval with your original X values to get the Y values of your derivative and plot that with hold on so it doesn't erase your original plot

##### 1 Comment

John D'Errico
on 31 Jul 2016

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!