How can one calculate Differentiation of matrix array with time as first column and data as second column ?

16 次查看(过去 30 天)
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.

回答(2 个)

dpb
dpb 2022-10-11
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 个评论
Shiv Nileshkumar Matliwala
As you can see, This is the plot of my data set. Now i want to do the differentiation of this curve shown here.
All i know is when we do differentiation of ramp input, we get step input. but i want to do the differentiation into matlab script by writing code.
Here this cruve has 80000 data values.
By using your code what i got is as below. And this is not my expected result.
Can you please help me with this ??
dpb
dpb 2022-10-13
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
Torsten 2022-10-13
B = [A(:,1),gradient(A(:,2))./gradient(A(:,1));
plot(B(:,1),B(:,2))

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by