How to read a text file with irregular timestamp data using detectImportOptions function ?
28 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Chuguang Pan
am 26 Nov. 2025 um 7:16
Kommentiert: Chuguang Pan
am 26 Nov. 2025 um 9:28
I want to read the condition monitoring datas stored in the text file. The data text file has 7 colums, where the first colum represents the sample time and the rest are the sensor datas. Portion of the data is illustrated in the attached file. I have tried to use the detectImportOptions function for importing the data into MATLAB workspace, yet the detectImportOptions function can not detect the file content correctly. Which function should I use to import this data file ?
opts = detectImportOptions("sampleDataFile.txt","Delimiter"," ");
preview("sampleDataFile.txt",opts)
0 Kommentare
Akzeptierte Antwort
Stephen23
am 26 Nov. 2025 um 8:28
Bearbeitet: Stephen23
am 26 Nov. 2025 um 9:20
The file that you uploaded is tab delimited, not space delimited as you specified. Once you provide the correct delimiter importing the file content will be a lot easier:
fnm = 'sampleDataFile.txt';
opt = detectImportOptions(fnm, 'Delimiter','\t');
preview(fnm,opt)
Note that calling DETECTIMPORTOPTIONS is not required, you can simply call READTABLE directly:
tbl = readtable(fnm, 'Delimiter','\t');
tbl.Var1 = datetime(tbl.Var1, 'TimeZone','-07:00', 'InputFormat','u-M-d_H:m:s.SSSSS_Z', 'Format','u-MM-dd HH:mm:ss.SSSSS Z')
Note that REDATBLE does not handle timezones, so you will have to call DATETIME afterwards.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!