How to check multiple lines?

8 Ansichten (letzte 30 Tage)
Peter Fang
Peter Fang am 16 Apr. 2022
Kommentiert: Peter Fang am 16 Apr. 2022
Hi everyone.
I have problem in checking lines with words i need to find in file .txt.
This is the function that I found out:
function B=Check
B=struct('Day','','Quantity','');
%Read file
filename='log.txt';
id=fopen(filename,'r');
data=fgetl(id);
%Close file
fclose(id);
ind=strfind(data,'Priting Done');
B.Day=data(1:9);
B.Quantity=data(70:end);
end
But this function can only check one line. I don't know how to check multiple lines.
Please help me.

Antworten (1)

Walter Roberson
Walter Roberson am 16 Apr. 2022
ind=strfind(data,'Priting Done');
You do not use the output of ind . As far as your function is concerned, you might as well not have bothered doing the comparison. You should be doing something different there.
data=fgetl(id);
That only reads one line. If you want to use fgetl() you should be looping.
Hint: fileread() and regexp()

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by