Problems reading a textfile; fgetl reads *****
Mostrar comentarios más antiguos
Hello,
I am trying to read text files of this format
1 1 1951 5.8
2 1 1951 0.0
3 1 1951 3.4
4 1 1951 0.0
5 1 1951 0.0
6 1 1951 0.0
... (until 2099, there are 54422 lines in each file).
Reading the files works well until for example
23 2 1997 171.7
which is read as
23 2 1997 *****
if I use fgetl, or if I continue reading the file with fscanf (e.g.
A=fscanf(fid,'%d %d %d %f',4)
nothing is read in for A(4).
If I open the file in Notepad++ it looks normal, the numbers are seperated by 1 to 3 blanks, the file has Unix line endings. Opening the file in Notepad++ and saving it solves the problem, but I have 294000 files, so that's not an option. If I skip that particular line, there is also no problem reading the other lines of the file. The problem only occurs every few thousand files.
This seems very weired. Does anybody have an idea, what the problem could be?
Thanks a lot, Doris
Respuesta aceptada
Más respuestas (1)
Jan
el 18 de Nov. de 2011
0 votos
Please show us how you open the file. Is it a problem of a Unicode conversion? Then read the line using fgetl and convert the values by double - anything above 255?!
How do you exactly determine that "23 2 1997 ***" is read? This is not trivial, because FSCANF does not reply numbers, if the reply has different types.
A really strange problem. But I've never seen Matlab acting magically. Therefore I'm convinced that it is a problem in the code.
3 comentarios
Doris
el 18 de Nov. de 2011
Jan
el 18 de Nov. de 2011
@Doris: Wow. Strange.
Walter Roberson
el 18 de Nov. de 2011
Try opening the file with 'rt' instead of 'r'
Categorías
Más información sobre File Operations 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!