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

조회 수: 8 (최근 30일)
M
M 2019년 4월 24일
답변: dpb 2019년 4월 24일
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
dpb
dpb 2019년 4월 24일
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 2019년 4월 24일
편집: M 2019년 4월 24일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2019년 4월 24일
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.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by