Using a function strncmp
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MIHYUN
am 16 Jan. 2014
Kommentiert: MIHYUN
am 22 Jan. 2014
I have a Text file.
And I want to ignore if the first character of the line begins with #.
Also if it begins without # , I want to output.
The code I wrote is as follows .
fid=fopen('asdf1.txt', 'r');
tline=fgetl(fid);
while ischar(tline)
if strncmp(tline,'#',1);%%this part is problem.
Please tell me what to do.
Thank in advance.
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 16 Jan. 2014
Bearbeitet: Azzi Abdelmalek
am 16 Jan. 2014
out=[];
fid=fopen('asdf1.txt');
tline=fgetl(fid);
while ischar(tline)
if ~strncmp(tline,'#',1);
out{end+1}=tline;
end
tline=fgetl(fid);
end
fclose(fid)
But you can just compare them with
if tline(1)=='#"
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!