Problems reading a textfile; fgetl reads *****
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Jan
2011년 11월 18일
0 개 추천
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
Doris
2011년 11월 18일
Jan
2011년 11월 18일
@Doris: Wow. Strange.
Walter Roberson
2011년 11월 18일
Try opening the file with 'rt' instead of 'r'
카테고리
도움말 센터 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!