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

6 vues (au cours des 30 derniers jours)
M
M le 24 Avr 2019
Réponse apportée : dpb le 24 Avr 2019
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 commentaires
dpb
dpb le 24 Avr 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 le 24 Avr 2019
Modifié(e) : M le 24 Avr 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

Connectez-vous pour commenter.

Réponses (1)

dpb
dpb le 24 Avr 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.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by