Hi,

I am trying to find the first and second derivates of a set of data points I've imported. I tried using the diff function but that just gave me an error. Also how would i create two seperate plots for each differentiation operation?

Thank you

Answer by dpb
on 24 Apr 2019

That's essentially trivial file that

data=csvread('data_10.csv');

data(:,2)=[nan;diff(data(:,1))]; % first difference

data(:,3)=[nan(2,1); diff(data(:,1),2)]; % second difference

will leave you with an array of three columns for data, first and second differences, respectively. The difference vectors are each one element shorter than the previous of course, so I used NaN as filler so plotting routines will ignore them silently. Since they're columns, simply

plot(data)

will plot all three on one axes; you can select columns as desired and/or use two axes or whatever for aesthetics as desired.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## dpb (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/458107-am-trying-to-find-the-first-and-second-derivates-of-a-set-of-data-points-i-ve-imported#comment_697505

## M (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/458107-am-trying-to-find-the-first-and-second-derivates-of-a-set-of-data-points-i-ve-imported#comment_697506

## KSSV (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/458107-am-trying-to-find-the-first-and-second-derivates-of-a-set-of-data-points-i-ve-imported#comment_697509

## dpb (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/458107-am-trying-to-find-the-first-and-second-derivates-of-a-set-of-data-points-i-ve-imported#comment_697528

## M (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/458107-am-trying-to-find-the-first-and-second-derivates-of-a-set-of-data-points-i-ve-imported#comment_697703

Sign in to comment.