To calculate the derivative of a time history in MATLAB, you can use the following steps:
t
and the signal vector x
.dt
as the difference between two consecutive time values.diff
function to calculate the difference between two consecutive signal values.dt
to obtain the derivative.Here's the code:
main.m416 chars25 lines
This code generates two subplots. The top one shows the original signal, and the bottom one shows its derivative. Note that the diff
function returns a vector that is one element shorter than the original signal, which is why we need to remove the last element of the t
vector before plotting the derivative.
gistlibby LogSnag