MATLAB Answers

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

조회 수: 1(최근 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);
but this is not working as intended, how can I do it?

  댓글 수: 1

로그인 to comment.

채택된 답변

Fabio Freschi
Fabio Freschi 4 Dec 2019
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

로그인 to comment.

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by