Test EOF while reading a file using csvread function
이전 댓글 표시
I am currently reading a .csv file in matlab using csvread function, and I am specifying where to begin and end reading. I would like to know if I am able to test if the current ending position extends beyond the end of file. Thank you. Andrei
답변 (2개)
Titus Edelhofer
2011년 5월 2일
Hi Andrei,
not directly. There are several possibilities though: if you edit csvread, you see the call to dlmread. If you edit dlmread, you see somewhere around line 149 (depending on MATLAB version) a call to close the file:
fclose(fid);
So one option would be to copy both files to your local folder, rename them to e.g. mycsvread and mydlmread and before closing the file add something like
atTheEnd = feof(fid);
Or you could get the number of lines by
fid = fopen(filename, 'rt');
t = textscan(fid, '%s', 'delimiter', '\n');
nRows = length(t{1});
fclose(fid);
and compare nRows with you row parameter to csvread.
Titus
카테고리
도움말 센터 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!