Derivative of unequally spaced data points without decreasing the length of a vector?

22 views (last 30 days)
Hello Matlab,
I have data ponts that are not equally spaced
x=[0.097
0.477
0.934
4.835
15.590
46.645
69.371
100.709
165.249
277.846
382.978
1000.64
1519.83
1991.60
2544.96
3023.40
3589.94
4159.93
4473.43
5186.36
6316.71
7134.15
9125.71
10571.90
12565.82
14916.64
16859.92
];
y=[20.96
21.33
20.77
20.96
21.14
21.33
20.24
19.71
17.90
15.98
14.51
10.05
8.37
7.40
6.49
6.05
5.54
5.17
4.82
4.57
4.26
3.87
3.52
3.25
3.08
2.80
2.61
];
dydx = diff(y(:))./diff(x(:))
z= y.*dydx;
First is dydx the right way to differentiate the data points? Second dydx will give me will give me one element shorter than y and have trouble calculating z. What is the best way to calculate z without shortening. I'm currently using shorten the y axis:
z= y(2:end).*dydx;
However, I dont like shorting my y axis.
Any help is appreciated. Thanks GH

Answers (1)

Walter Roberson
Walter Roberson on 5 Feb 2018
gradient(y, x)

Categories

Find more on Graphics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!