How to read a text file with irregular timestamp data using detectImportOptions function ?
28 ビュー (過去 30 日間)
古いコメントを表示
Chuguang Pan
2025 年 11 月 26 日 7:16
コメント済み: Chuguang Pan
2025 年 11 月 26 日 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 件のコメント
採用された回答
Stephen23
2025 年 11 月 26 日 8:28
編集済み: Stephen23
2025 年 11 月 26 日 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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!