weird issue with fgetl
Mostrar comentarios más antiguos
Hello,
I have a text document called 'num.dat' that contains:
969592914
969592915
969592916
969592917
when I execute the commands:
fid = fopen('num.dat','rt');
fgetl(fid)
fgetl(fid)
I get the output:
ans =
'969592914'
ans =
''
Instead of (as I expected):
ans =
'969592914'
ans =
'969592915'
And I can't figure out why, thanks in advance!
Respuestas (2)
KSSV
el 1 de Feb. de 2017
That is not weird. You should know that the second line is empty so the output is ''. To get your expected behavior remove the blank spaces. Or alternatively you may try:
clc; clear all ;
fid = fopen('num.dat','rt');
l1 = fgetl(fid)
while ~isa(l1,'double')
l1 = fgetl(fid)
end
fclose(fid) ;
Walter Roberson
el 1 de Feb. de 2017
Editada: Walter Roberson
el 1 de Feb. de 2017
0 votos
You posted here with a format that suggests there are blank lines in the input. If so then the second fgetl() is going to retrieve the blank line after the first line. fgetl() does not skip empty lines.
If this does not seem to be the issue, please attach a copy of a file that it happens for.
Categorías
Más información sobre General Applications en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!