How to read a text file with irregular timestamp data using detectImportOptions function ?
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Chuguang Pan
el 26 de Nov. de 2025 a las 7:16
Comentada: Chuguang Pan
el 26 de Nov. de 2025 a las 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 comentarios
Respuesta aceptada
Stephen23
el 26 de Nov. de 2025 a las 8:28
Editada: Stephen23
el 26 de Nov. de 2025 a las 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!