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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!