필터 지우기
필터 지우기

How to read text file

조회 수: 2 (최근 30일)
Kanakaiah Jakkula
Kanakaiah Jakkula 2015년 8월 8일
댓글: Kanakaiah Jakkula 2016년 1월 7일
Hi,
I have a text file, I want to store the following information:
Data1: Information specified below "Additional information":
1. Alarmtype1 heater volt:1670890
2. system error:5480
3. Alaram, voltage, event ID:46754
4. warning, id:15643
5. warning current, event id:76542
Data2: Information specified below "xy(24 points)":
-14 0.28
-13 0.27
-12 0.26
-11 0.25
-10 0.24
-9 0.23
-8 0.23
-7 0.22
-6 0.22
-5 0.22
-4 0.22
-3 0.22
-2 0.22
-1 0.22
0 0.23
1 0.22
2 0.22
3 0.22
4 0.22
5 0.22
6 0.22
7 0.23
8 0.23
9 0.23
10 0.24
11 0.26
12 0.29
Many many thanks in advance,

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 8일
fid=fopen('RainFallReport9.txt')
s=textscan(fid,'%s','delimiter','\n')
fclose(fid)
s=s{:}
idx=find(~cellfun(@isempty,regexpi(s,'additional information')))
b=s(idx:end)
  댓글 수: 8
Kanakaiah Jakkula
Kanakaiah Jakkula 2015년 8월 9일
편집: Kanakaiah Jakkula 2015년 8월 9일
Sir,
Thank you very much, but lastly I want to ask you about:
c=b(3:7);
Acually the below one is not a fixed one, but it will vary:
1. Alarmtype1 heater volt:1670890
2. system error:5480
3. Alaram, voltage, event ID:46754
4. warning, id:15643
5. warning current, event id:76542
I mean 1~5 will vary, may be some time 1~3, some time 1~4, or some time 1~8 or what ever. That is why instead I want to stop when dotted line appears (--------) for this Data2 storing.
One more thing, I have to read multiple text files from the directory at the same time. I attached herewith four text files for example.
May I humbly request you to kinldy help,
Sincerely,
Your's
Kanakaiah Jakkula
Kanakaiah Jakkula 2016년 1월 7일
Sir,
I want to read multiple files, please help me which part of the code should be changed. Sincerely, Mekala

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

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by