MATLAB: How to turn a column of seconds into the datetime-type

datetimeMATLABtable

I have a table that looks like this:
TIME_s SD1_SPEED_MEASURED_1_rpm SD2_SPEED_MEASURED_1_rpm SD3_SPEED_MEASURED_1_rpm SD4_SPEED_MEASURED_1_rpm SD1_MOTOR_SPEED_rpm SD2_MOTOR_SPEED_rpm SD3_MOTOR_SPEED_rpm SD4_MOTOR_SPEED_rpm SD1_MOTOR_TORQUE_pct SD2_MOTOR_TORQUE_pct SD3_MOTOR_TORQUE_pct SD4_MOTOR_TORQUE_pct SD1_TORQUE_REF_B_pct SD2_TORQUE_REF_B_pct SD3_TORQUE_REF_B_pct SD4_TORQUE_REF_B_pct
______ ________________________ ________________________ ________________________ ________________________ ___________________ ___________________ ___________________ ___________________ ____________________ ____________________ ____________________ ____________________ ____________________ ____________________ ____________________ ____________________
242.2 -66.174 -69.167 -77.607 -74.388 -66.369 -69.19 -77.367 -73.986 -2.6341 -0.046144 0.34017 -0.7492 -1.97 -2.3501 -2.3501 -2.3501
242.18 -66.174 -69.167 -77.607 -74.388 -66.369 -69.19 -77.367 -73.986 -2.6341 -0.046144 0.34017 -0.7492 -1.97 -2.3501 -2.3501 -2.3501
242.16 -68.547 -72.838 -79.49 -77.035 -68.078 -72.151 -78.954 -75.901 -2.8352 -0.24927 -1.2125 -4.7041 -1.97 -1.97 -2.3501 -2.3501
242.14 -68.547 -72.838 -79.49 -77.035 -68.078 -72.151 -78.954 -75.901 -2.8352 -0.24927 -1.2125 -4.7041 -1.97 -1.97 -2.3501 -2.3501
242.12 -71.372 -75.556 -80.754 -79.204 -70.49 -74.884 -80.715 -78.217 -3.1016 -3.7407 -1.6364 -2.9571 -1.97 -1.97 -1.97 -1.97
...
0 0 0 0 0 0 0 0
Where the leftmost column records the time that has passed since the beginning of the recording in seconds. In a separate variable, I have stored the starting time of the recording in the datetime-type. In this example, the time is this:
zinterval =
datetime
18-Feb-2018 15:11:11
Now, is there any way to turn the value 0 in the column of seconds into the starting time, and then have all the following seconds be times in the datetime-type following the starting time?

Best Answer

The simple MATLAB solution using datetime and duration classes (no outdated datevec):
T.TIME_S = zinterval + seconds(T.TIME_s)
Note that using the variable name "TIME_s" is then a bit misleading (better would be "TIME" or something similar) and I would recommend avoiding overwriting your raw data. Here is a full working example:
>> T = array2table([242.2;242.18;242.16;242.14;242.12;0],'VariableNames',{'TIME_s'})
T =
TIME_s
______
242.2
242.18
242.16
242.14
242.12
0
>> zinterval = datetime('18-Feb-2018 15:11:11')
zinterval =
18-Feb-2018 15:11:11
>> T.TIME = zinterval + seconds(T.TIME_s)
T =
TIME_s TIME
______ ____________________
242.2 18-Feb-2018 15:15:13
242.18 18-Feb-2018 15:15:13
242.16 18-Feb-2018 15:15:13
242.14 18-Feb-2018 15:15:13
242.12 18-Feb-2018 15:15:13
0 18-Feb-2018 15:11:11