How can one calculate Differentiation of matrix array with time as first column and data as second column ?
29 views (last 30 days)
Show older comments
Hello everyone,
I have a problem solving the differentiation of vector. I have data with first column as time and second column as my data. Now, I want to calculate the derivative of this data and again want the matrix with same size. So, does anyone have any idea how can I make it ??
My matrix has 80,000 data value with time. So, I have 80,000 rows and 2 columns which are time and data values.
Please help me with this.
In another way i can explain as, suppose I have a data of ramp input and there are 80,000 point values for specific time values. So, now I want to calculate derivative of this ramp input. So, If you have any idea please help me.
If you still have doubt then please write in comment. I will try to explain it more in details.
Thank you.
0 Comments
Answers (2)
dpb
on 11 Oct 2022
g=diff(v(:,2))./diff(v(:,1)); % numerical gradient
The gradient vector estimate will be one element shorter than the input vector; if for convenience it is desired to maintain the length, then augment the beginning element
g=[0;diff(v(:,2))./diff(v(:,1))]; % numerical gradient with initial 0 value
IFF the time steps are uniform, you could instead use
h=diff(v(1:2,1)); % the fixed delta_t
g=[0;gradient(v(:,2)),h]; % numerical gradient with initial 0 value, uniform delta_t
2 Comments
dpb
on 13 Oct 2022
That looks like differential between points is just roundoff...
Attach a .mat file with a sample of your data -- it could be just the first hundred points or so would be enough to find out what's going on.
I'll amend my Answer to agree with @Torsten, however, that gradient is better than the first difference; I had forgotten it uses central differences and not the simple differences that diff does, so will give a smoother estimate that may help. Also, though, it does return a full-length vector automagically so you don't need to augment the front end; just use
g=gradient(v(:,2))./gradient(v(:,1)); % numerical gradient variable sampling
if the time spacing is nonuniform or
g=gradient(v(:,2),h); % numerical gradient fixed sampling, h
for fixed sample rate.
Torsten
on 13 Oct 2022
B = [A(:,1),gradient(A(:,2))./gradient(A(:,1));
plot(B(:,1),B(:,2))
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!