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

조회 수: 1 (최근 30일)
Vishnu Dhakad
Vishnu Dhakad 2018년 6월 8일
댓글: Vishnu Dhakad 2018년 6월 11일
I have a text file (please find the attachment).
how to read the only number data from the file???

답변 (1개)

Peter Perkins
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.
  댓글 수: 1
Vishnu Dhakad
Vishnu Dhakad 2018년 6월 11일
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);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by