How to read required information from particular line

Hi, I want to read from particular line as follows:
From the text file I want to read after the below line:
Additional information:
Alarm:100567
system error alarm:5480
I want to save information above the line where it appears 5480. The line above this is "Alarm:100567" Finally I want to note 100567 in my output.
Please help me how to do this. (I tried with strtok, but not successes).
Many thanks in advance

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 11 de Jul. de 2015
Editada: Azzi Abdelmalek el 11 de Jul. de 2015
fid=fopen('file.txt')
a=fgetl(fid)
k=0
while ischar(a)
k=k+1
r{k,1}=a
a=fgetl(fid)
end
fclose(fid)
id=find(~cellfun(@isempty,regexp(r,'5480')))
c=regexp(r(id-1),'\d+','match')
out=str2double(c{1})
If this repeats in your file
id=find(~cellfun(@isempty,regexp(r,'5480')))
for k=1:numel(id)
c=regexp(r(id(k)-1),'\d+','match')
out(k)=str2double(c{1})
end

Categorías

Más información sobre Data Import and Analysis en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 11 de Jul. de 2015

Editada:

el 11 de Jul. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by