how to calculate the elapsed time between rows
Show older comments
Hi, I have a 11619x6 matrix of the form [No.Data, YY, mm, dd, hour, sec]
1 1968 1 1 7 50 50.76
2 1968 1 4 11 37 8.190
3 1968 1 11 23 17 0.1400
4 1968 1 14 21 21 59.06
5 1968 1 17 19 34 55.70
6 1968 1 18 21 22 32.22
etc...
and I want to calculate the elapsed time between the 1st row and the 2nd, and then between the 1st row and the 3rd, then between the 1st row and the 4th and so on...
My thought was to do something simple without using a for loop
T= x(1:end-1,2:7);
Tn= x(2:end,2:7);
dt=etime(Tn,T);
but it didn't work. Can anyone give me an idea how to solve this?
Thanks!
Accepted Answer
More Answers (1)
dpb
on 31 Aug 2014
Can't just subtract times in hr,min,sec form since there's rollover. Convert to datenums and subtract them then convert back to whatever units desired...
>> dn=datenum(t(:,2:end)); % convert to datenums
>> dt=dn(2:end)-dn(1) % compute since first (days.fractions_thereof)
dt =
3.1571
10.6432
13.5633
16.4889
17.5637
>> dt*24 % and difference in hours
ans =
75.7715
255.4359
325.5190
395.7347
421.5282
>>
1 Comment
Angeliki Efstathiou
on 31 Aug 2014
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!