central difference method
10 次查看(过去 30 天)
显示 更早的评论
How can I calculate the central difference for set of data using matlab If I have big data.Could any one help me to do it for this small data so I can I apply to my data X 0.225 0.30 0.35 0.40 0.45 0.475 Y 0.251 0.90 2.02 3.63 7.2 9.800
0 个评论
采纳的回答
Jan
2012-4-18
You can simply use:
gradient(X, Y)
Then the first and the last element are forward and backward differences respectively. But all interior elements are central differences.
For large data sets FEX: DGradient is faster (10 to 16 times) than Matlab's gradient. In addition it can calulate the 2nd order approximation, when X is not uniformly distributed.
3 个评论
Jan
2021-2-15
t = linspace(0, 2*pi, 1000);
x = sin(t);
dx = (x(11:5:end) - x(1:5:end-10)) / (10 * diff(t(1:2)));
plot(t(1:5:end-5), cos(t(1:5:end-5)), 'ro');
hold on
plot(t(5:5:end-10),dx)
Muhammad Hammad Malik
2021-2-15
编辑:Muhammad Hammad Malik
2021-2-16
@Jan thanks for the kind response. i have checked your code, but unable to understand well. why you use 11:5 and cos.
pls see what i have done, i am attaching here, the issue is i am unable to add window overlap.I also can change the window size to bigger or smaller, not restricted to use just 10.
The one you mentioned is working but how i can plot that with my time vector "IMU_ULISS.time" (1x25805), and i changed this time vector to plot mine as you can see.
Grad =gradient(Data_filtered(1:window:end),window)
figure;
plot(IMU_ULISS.time(1:window:end),Grad)
time_modified=IMU_ULISS.time(1:window:end)
hold onplot(time_modified(ceil(find(IMU_ULISS.step_instant_target(1,:)>0)/window)),Grad(ceil(find(IMU_ULISS.step_instant_target(1,:)>0)/window)),'r');
hold on
更多回答(1 个)
abdulhadi khalifa
2012-4-18
1 个评论
Jan
2012-4-18
The output of GRADIENT *is* the slope. See my former answer.
It would be more helpful if you reply to the different ideas you got in your other postings concerning this problem. Simply posting the problem repeatedly in new threads wastes the time of all who want to assist.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!