Filter löschen
Filter löschen

central difference method

10 Ansichten (letzte 30 Tage)
abdulhadi khalifa
abdulhadi khalifa am 18 Apr. 2012
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

Akzeptierte Antwort

Jan
Jan am 18 Apr. 2012
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 Kommentare
Jan
Jan am 15 Feb. 2021
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
Muhammad Hammad Malik am 15 Feb. 2021
Bearbeitet: Muhammad Hammad Malik am 16 Feb. 2021
@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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

abdulhadi khalifa
abdulhadi khalifa am 18 Apr. 2012
I want to calculate the slope by this method for y and X how I can do it
  1 Kommentar
Jan
Jan am 18 Apr. 2012
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by