How to pull dates out of character array, to get a datetime array. The character array was created from a log file in txt format.
조회 수: 3 (최근 30일)
이전 댓글 표시
This is related to this Q&A. Seems like I am close. Any help is apprecaited.
%Pull out dates
matchStr= 'METRIC ALERT LOG';
charArray= char(lines2023(contains(lines2023,matchStr)))
charArray = 89×43 char array
'METRIC ALERT LOG - Sun Jan 1 13:15:20 2023'
'METRIC ALERT LOG - Sun Jan 1 21:30:20 2023'
...
'METRIC ALERT LOG - Thu Dec 28 12:00:20 2023'
'METRIC ALERT LOG - Thu Dec 28 12:15:20 2023'
inDateFormat= "'METRIC ALERT LOG - *** 'MM dd hh:mm:ss yyyy";
dateTimeArray=datetime(charArray(:,:),'InputFormat',inDateFormat); % convert date strings to datetime
Error using datetime
Unable to convert the text to datetime using the format ''METRIC ALERT LOG - *** 'MM dd hh:mm:ss yyyy'.
댓글 수: 0
채택된 답변
Cris LaPierre
2024년 2월 7일
편집: Cris LaPierre
2024년 2월 7일
charArray = ['METRIC ALERT LOG - Sun Jan 1 13:15:20 2023'
'METRIC ALERT LOG - Sun Jan 1 21:30:20 2023'
'METRIC ALERT LOG - Thu Dec 28 12:00:20 2023'
'METRIC ALERT LOG - Thu Dec 28 12:15:20 2023']
inDateFormat= "'METRIC ALERT LOG - 'eee MMM dd HH:mm:ss yyyy";
dateTimeArray=datetime(charArray,'InputFormat',inDateFormat)
댓글 수: 2
Cris LaPierre
2024년 2월 7일
ah, I just forgot to update the code once I found the correct format. I'll update.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!