How can I get an array of velocity if I have an array of position and another array of time

조회 수: 37 (최근 30일)
So I have two arrays, one with position and other with time but now I want to get a vector with the velocity over that time, ive seen it being done many ways but I cant get none to work, this is an example of my code:
pos=[0 2 4 8 16 32 64];
t=[0 0.1 0.2 0.3 0.4 0.5 0.6];
V= diff(pos)/diff(t);
plot(t,V)
but this is not working as intended, how can I do it?
Thanks!

채택된 답변

Fabio Freschi
Fabio Freschi 2019년 12월 4일
First, you need a element-wise division
pos = [0 2 4 8 16 32 64];
t = [0 0.1 0.2 0.3 0.4 0.5 0.6];
V = diff(pos)./diff(t);
Then you must realize that the size of V equals the size of t and pos minus one. So you need to reduce the t vector. I usually set a new time vector at the mid-points of the original vector
t_new = (t(1:end-1)+t(2:end))/2; % [0.05 0.15 0.25 ...]
Now you can plot
figure, plot(t_new,V);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometric Geodesy에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by