datenum with multiple formats

조회 수: 1 (최근 30일)
Connor Brackley
Connor Brackley 2019년 2월 4일
편집: Connor Brackley 2019년 2월 13일
Hi All,
I am trying to convert a string array into a date serial.
When i use xlsread to import an excel document, it imports the following string array.
'01/01/2015 9:00:00 PM'
'01/01/2015 10:00:00 PM'
'01/01/2015 11:00:00 PM'
'02/01/2015'
'02/01/2015 1:00:00 AM'
'02/01/2015 2:00:00 AM'
'02/01/2015 3:00:00 AM'
in general it is in the format:
'mm/dd/yyyy HH:MM:SS PM'
but the imported 12am timestamps are formatted without the time. So when I provided datenum with that format:
datenum(txt,'mm/dd/yyyy HH:MM:SS PM')
it has an error when it it gets to the items without the time string.
Then if I dont provide the format, it assumes it is in the form 'dd/mm ...'
How can I efficently convert this array into date serials?
Thanks!
  댓글 수: 1
madhan ravi
madhan ravi 2019년 2월 4일
Use readtable() to read the file.

댓글을 달려면 로그인하십시오.

채택된 답변

Connor Brackley
Connor Brackley 2019년 2월 13일
편집: Connor Brackley 2019년 2월 13일
"Use readtable() to read the file."
Thanks madhan ravi, using read table instead did the trick

추가 답변 (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