Added file
Reading content of a file using readtable return NaT for Time
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Life is Wonderful
am 20 Aug. 2019
Bearbeitet: Life is Wonderful
am 5 Sep. 2019
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.
Akzeptierte Antwort
Walter Roberson
am 5 Sep. 2019
Bearbeitet: Andrei Bobrov
am 5 Sep. 2019
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 Kommentare
Weitere Antworten (1)
Andrei Bobrov
am 5 Sep. 2019
Bearbeitet: Andrei Bobrov
am 5 Sep. 2019
T = readtable('eventlog.txt','format',...
'%d %{yyyy-MM-dd HH:mm:SS}D %s %s %s','delimiter','|',...
'ReadVariableNames',false);
1 Kommentar
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!