MATLAB: How to calculate the elapsed time between rows

date vectoretime

Hi, I have a 11619×6 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!

Best Answer

This works:
M = [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];
MT = M(:,2:7); % Time Vectors
for k1 = 2:size(MT,1)
MET(k1,:) = etime(MT(k1,:), MT(1,:)); % Vector of Elapsed Times
end
You can do it without a loop, but you have to provide a matrix of MT(1,:) values equal in length to the rest of the time vectors:
MT1 = repmat(MT(1,:), size(MT,1)-1, 1); % Matrix of ‘MT(1,:)’ Values
MET = etime(MT(2:end,:), MT1);
The loop takes about 8% longer than the repmat version in this example.