- 'Format' governs what the output looks like
- 'InputFormat' governs what the input looks like
Datetime won't recognise some cells
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a series of datetimes in the format 'HH:mm:ss.sss'. I am using the following code to convert from string into datetimes.
data.TimeofDay = datetime(data.TimeofDay,'Format','HH:mm:ss.sss')
In the attached .mat file, it contains the data file before and after the command above. For some reason, different values in the column are returned as NaT despite all rows seemingly being in the same format.
댓글 수: 1
the cyclist
2022년 6월 28일
편집: the cyclist
2022년 7월 9일
Relevant for both your code and some of the answers:
In your case, I believe MATLAB would have correctly inferred your input format, if had you left it unspecified:
datetime(data.TimeofDay)
채택된 답변
Cris LaPierre
2022년 6월 28일
For miliseconds, you want to use a capital 'S'.
load datetime-problem.mat
datetime(databackup.TimeofDay,'Format','HH:mm:ss.sss')
% corrected
datetime(databackup.TimeofDay,'Format','HH:mm:ss.SSS')
댓글 수: 0
추가 답변 (2개)
the cyclist
2022년 6월 28일
편집: the cyclist
2022년 6월 28일
Two minor but important changes to your syntax:
datetime(data.TimeofDay,'InputFormat','HH:mm:ss.SSS')
Note that I used
- 'InputFormat' instead of 'Format'
- .SSS instead of .sss
댓글 수: 0
Voss
2022년 6월 28일
load datetime-problem.mat
databackup.TimeofDay
% original Format specification:
datetime(databackup.TimeofDay,'Format','HH:mm:ss.sss')
% corrected Format specification:
datetime(databackup.TimeofDay,'Format','hh:mm:ss.SSS')
댓글 수: 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!