How to read text file
Mostrar comentarios más antiguos
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,
Respuestas (1)
Azzi Abdelmalek
el 8 de Ag. de 2015
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 comentarios
Kanakaiah Jakkula
el 8 de Ag. de 2015
Azzi Abdelmalek
el 8 de Ag. de 2015
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);
idx=find(~cellfun(@isempty,regexp(b,'xy','match')));
a=regexp(b(idx+1:end-1),'[\.\d]+','match');
data1=str2double(reshape([a{:}],[],2));
c=b(3:7);
d=regexp(c,'\d+(?=\d)','match');
data2=str2double([d{:}])';
data1
data2
Kanakaiah Jakkula
el 8 de Ag. de 2015
Azzi Abdelmalek
el 8 de Ag. de 2015
Change this line
a=regexp(b(idx+1:end-1),'[\.-\d]+','match')
Kanakaiah Jakkula
el 8 de Ag. de 2015
Azzi Abdelmalek
el 8 de Ag. de 2015
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);
idx=find(~cellfun(@isempty,regexp(b,'xy','match')));
a=regexp(b(idx+1:end-1),'[-\.\d]+','match');
data1=str2double(reshape([a{:}],2,[])');
c=b(3:7);
d=regexp(c,'\d+(?=\d)','match');
data2=str2double([d{:}])';
data1
data2
Kanakaiah Jakkula
el 9 de Ag. de 2015
Editada: Kanakaiah Jakkula
el 9 de Ag. de 2015
Kanakaiah Jakkula
el 7 de En. de 2016
Categorías
Más información sobre Text Data Preparation en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!