am trying to find the first and second derivates of a set of data points I've imported

8 views (last 30 days)
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
  5 Comments
dpb
dpb on 24 Apr 2019
Undefined function 'diff' for input arguments of type 'table'.
You insist on making it difficult by not providing sufficient information but M is the name of the overall table -- you've got to reference whatever particular variable it is out of the table to operate on...something like
dy=diff(M.X);
where X is the name of the variable you want to take difference of. Of, course, to actualy compute a derivative, you need the difference of both the displacement and time vectors if it were the velocity trying to compute--
v=diff(M.x)./diff(M.t);
M
M on 24 Apr 2019
Edited: M on 24 Apr 2019
i didnt know i could attach a file im not intending to make it difficult. i only have one row of data and i need the first and second derivatives of the data

Sign in to comment.

Answers (1)

dpb
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.

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!