MATLAB: From date and time in different columns to datetime

arraydatedatetimetime

Hey, I have an array with date (yyyy-mm-dd) in one columns and time (hh:mm:ss) in another like this:
2017-09-29 21:00:00
2017-09-29 22:00:00
2017-09-29 23:00:00
2017-09-30 00:00:00
2017-09-30 01:00:00
2017-09-30 02:00:00
2017-09-30 03:00:00
How can I make this array into a datetime array?

Best Answer

Assuming your data is stored in CSV file like the attached, readtable function automatically recognize that 1st and 2nd column are datetime and duration. So, the following can make the datetime vector you want.
T = readtable('data1.csv');
time = T{:,1}+T{:,2};