how to combine date and time

3 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2020-2-22
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by