How to read only number from the number and character mixed text file???

3 views (last 30 days)
I have a text file (please find the attachment).
how to read the only number data from the file???

Answers (1)

Peter Perkins
Peter Perkins on 8 Jun 2018
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.
  1 Comment
Vishnu Dhakad
Vishnu Dhakad on 11 Jun 2018
thanks for your answer
I have read it as your guidance but Var3 gives 'No Data'
after these reading, I want to read the following written code but getting ERROR
If you have any idea please help
fmlds = fopen('Q.table');
MD = textscan(fmlds, '%c, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f');
fclose(fmlds);

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!