Reading content of a file using readtable return NaT for Time
조회 수: 2 (최근 30일)
이전 댓글 표시
Please find the attached file. I want to use readtable to parse the file using readtable function.
I want Date and message content separatly done.
채택된 답변
Walter Roberson
2019년 9월 5일
편집: Andrei Bobrov
2019년 9월 5일
filename = 'eventlog.txt';
opt = detectImportOptions(filename);
opt = setvartype(opt, 5, 'char');
datatable = readtable(filename, opt);
datatable{:,2} is now the datetime entry, and datatable(:,[3 4 5]) are the fields.
As the fields are delimited, it is not completely clear whether you wanted everything to the end of the line as a single character vector complete with '|' inside, or if you wanted the fields broken out. The above breaks them out.
string(datatable{:,3}) + " | " + string(datatable{:,4}) + " | " + string(datatable{:,5})
would put the fields back together, except with an extra trailing " | " on the lines that had only 4 fields originally.
댓글 수: 2
추가 답변 (1개)
Andrei Bobrov
2019년 9월 5일
편집: Andrei Bobrov
2019년 9월 5일
T = readtable('eventlog.txt','format',...
'%d %{yyyy-MM-dd HH:mm:SS}D %s %s %s','delimiter','|',...
'ReadVariableNames',false);
댓글 수: 1
참고 항목
카테고리
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!