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

 Respuesta aceptada

Jan
Jan el 18 de Abr. de 2012

0 votos

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 comentarios

Muhammad Hammad Malik
Muhammad Hammad Malik el 14 de Feb. de 2021
@Jan i am asking here because already a post here, if you want i can have a new post.
i want to calculate gradient (central difference) from my filtered data. Want to calculate with window size=10samples and 50%overlap to previous window, how can do this.
Jan
Jan el 15 de Feb. de 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 el 15 de Feb. de 2021
Editada: Muhammad Hammad Malik el 16 de Feb. de 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

Iniciar sesión para comentar.

Más respuestas (1)

abdulhadi khalifa
abdulhadi khalifa el 18 de Abr. de 2012

0 votos

I want to calculate the slope by this method for y and X how I can do it

1 comentario

Jan
Jan el 18 de Abr. de 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.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 18 de Abr. de 2012

Editada:

el 16 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by