How to change time intervals to time elapsed

4 visualizaciones (últimos 30 días)
Rewsen Yildirim-Nevay
Rewsen Yildirim-Nevay el 2 de Feb. de 2021
Comentada: Steven Lord el 2 de Feb. de 2021
I have time data in a column vector which was measured in intervals of time meaning I can't plot this against distance to get a velocity graph.
How do I create a new column vector with the total time elapsed up to each point? (e.g. 1,2,1,1,3 to 1,3,4,5,8)
Thanks

Respuesta aceptada

SHIVAM KUMAR
SHIVAM KUMAR el 2 de Feb. de 2021
You can do this simply using a loop
a=[1 2 1 1 3]
sum=0;
result=zeros(1,length(a));
for i=1:length(a)
sum=sum+a(i);
result(i)=sum;
end
It this is fine accept the answer.
  3 comentarios
Steven Lord
Steven Lord el 2 de Feb. de 2021
The cumsum function also works with a duration array, if you want to make it clear that your time data does represent time.
m = minutes(randi([0 9], 1, 7)) + seconds(randi([0 59], 1, 7));
m.Format = 'mm:ss'
m = 1×7 duration array
00:28 01:32 09:51 03:38 00:03 04:53 03:17
n = cumsum(m)
n = 1×7 duration array
00:28 02:00 11:51 15:29 15:32 20:25 23:42

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by