How to read only number from the number and character mixed text file???
1 回表示 (過去 30 日間)
古いコメントを表示
I have a text file (please find the attachment).
how to read the only number data from the file???
0 件のコメント
回答 (1 件)
Peter Perkins
2018 年 6 月 8 日
You are probably better off reading the whole file into a table using readtable, with TreatAsEmpty set to "No Data". In recent versions of MATLAB, you'll get the date and the time as datetimes and durations. Then do whatever thinning you want in MATLAB.
>> t = readtable('MetDLS_DATA.txt','TreatAsEmpty','No Data')
t =
134×14 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13 Var14
____ __________ ________ _______ _______ _________ _______ __________ ________ _____ _____ _____ _____ ______
'D' 31/05/2018 02:01:29 72.7236 24.5821 1156.1999 6.0704 31/05/2018 07:31:14 25.97 66.47 29.74 54.01 881.26
'D' 31/05/2018 02:01:31 72.7235 24.5821 1156.1999 6.2248 31/05/2018 07:31:16 25.96 66.62 29.73 54.03 881.26
'D' 31/05/2018 02:01:33 72.7234 24.5821 1156.1999 5.7618 31/05/2018 07:31:18 25.92 66.7 29.73 54.06 881.26
'D' 31/05/2018 02:01:35 72.7233 24.5821 1155.4 4.3728 NaT 07:31:20 25.9 66.72 29.71 54.08 881.26
'D' 31/05/2018 02:01:37 72.7232 24.5821 1154.1999 4.3728 31/05/2018 07:31:21 25.89 66.59 29.71 54.01 880.79
'N' NaT NaN NaN NaN NaN NaN 31/05/2018 07:34:16 26.96 62.42 29.38 54.36 881.73
'N' NaT NaN NaN NaN NaN NaN 31/05/2018 07:34:18 26.95 62.06 29.38 54.43 881.58
'N' NaT NaN NaN NaN NaN NaN 31/05/2018 07:34:20 26.92 61.73 29.38 54.43 881.73
'N' NaT NaN NaN NaN NaN NaN 31/05/2018 07:34:22 26.89 61.75 29.38 54.36 881.58
...
Turn that first variable into a categorical, and you're good. In versions before R2018a, readtable will read the times-of-day as text, you can use text2duration on the File Exchange to convert.
参考
カテゴリ
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!