How to read a text file with irregular timestamp data using detectImportOptions function ?
28 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Chuguang Pan
il 26 Nov 2025 alle 7:16
Commentato: Chuguang Pan
il 26 Nov 2025 alle 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 Commenti
Risposta accettata
Stephen23
il 26 Nov 2025 alle 8:28
Modificato: Stephen23
il 26 Nov 2025 alle 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Text Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!