MATLAB: How to plot velocity after differentiating displacement with respect to time

accelerationdifferentiationdisplacementvelocity

I have successfully managed to differentiate displacement to find velocity. However, i am then unable to plot a figure of velocity versus time, or differentiate again to find acceleration, as the vectors are of different sizes.
How can I fix this?
Thanks.

Best Answer

use the gradient function for the numerical derivative, not diff. (Use del2/4 for the second derivative.) The diff function does successive differences, so the output is one element shorter than the input. The gradient function is a numerical derivative function, so the output will be the same length as the input. See the documentation for the various functions for details.
Related Question