Calculating delta t from a dataset? Diff command.

2 views (last 30 days)
I have a very large dataset named Current that contains over a million rows. Here is an example of the first 15 lines:
Hour Min Second Line1 Line2 Power Dt
0 0 3 1.94 3.71 678 6
0 0 9 1.93 3.71 676.8 5
0 0 14 1.93 3.71 676.8 6
0 0 20 1.94 3.72 679.2 5
0 0 25 1.93 3.72 678 6
0 0 31 1.93 3.72 678 5
0 0 36 1.93 3.73 679.2 6
0 0 42 1.93 3.72 678 5
0 0 47 1.93 3.72 678 6
0 0 53 1.92 3.72 676.8 5
0 0 58 1.92 3.72 676.8 -54
0 1 4 1.92 4.99 829.2 5
0 1 9 1.92 5.02 832.8 6
0 1 15 1.92 5.02 832.8 11
0 1 26 1.92 5 830.4 6
I am trying to fill Dt, Delta T, with the change in time using
Current.Dt = diff(Current.Second);
There are two problems with this. 1. The Dt's need to be shifted down one. For example the second row should be 6 instead of 5 and the third 5 instead of 6. 2. The second problem is when the diff takes the value 4-58 it gets a the value of -54. This is incorrect. The time data was collected by the min so the value should actually be equal to 64-58 or 6.
I am not sure how to fix this and any help will be appreciated

Answers (1)

Star Strider
Star Strider on 5 Mar 2014
Edited: Star Strider on 5 Mar 2014
I suggest you consider the etime function. You’ll have to pad each 3-element time vector with leading zeros to get the six-element date vector, but it is probably the easiest solution to implement.

Categories

Find more on Shifting and Sorting Matrices 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!