MATLAB: How to combine date and time

datadata importMATLAB

So i have my data file attached
want to combine the data and time
then using the combined datetime produce different temptime graphs of diff days

Best Answer

In theory at least, datetime should be able to do this seamlessly using the timeofday function for the seconds. In practice, it cannot do it at all, at least when I tried it, so I resorted to datenum to do the necessary arithmetic to combine the dates and times.
Try this:
D = readtable('data.txt','ReadVariableNames',1);
DNS = datenum([zeros(size(D,1),5) D{:,2}]);
DND = datenum(compose('%s',D{:,1}),'dd/mm/yyyy');
DateTime = datetime(DND + DNS, 'ConvertFrom','datenum');
When I looked at the results with:
Check = DateTime([1:20:1000]);
it seemed to be converting them correctly. I may have gotten the days and months reversed, since the date format is not obvious. Correct that if necessary by changing ‘'dd/mm/yyyy'’ to ‘'mm/dd/yyyy'’.
The compose call takes a while, so in the interests of speed, save ‘DateTime’ to a .mat file to load quickly when you want to use it later.