~feof doesnt woek properly, how to fix the problem.
이전 댓글 표시
Hello,
I had a code in Matlab 2011 to read some file and it was working well. I upgraded to Matlab 2014 and now feof doesn't recognize the end of the file and remains in the while loop as below. What I should do now?
while (~feof(fileID))
[data,position] = textscan(fileID,'%f',82,'delimiter', '\t\t');
real_data{counter,:} = data;
counter = counter + 1;
end
댓글 수: 2
Guillaume
2015년 4월 29일
Can you attach a file that replicate the problem?
Very Determined
2015년 5월 3일
편집: Very Determined
2015년 5월 3일
Hello,
I have attached one of the files. I had to change the extension to .txt (from .log) as it was not allowed by this site. I have 18 files of the same type in a folder. Thanks for the help.
채택된 답변
추가 답변 (1개)
Image Analyst
2015년 5월 3일
0 개 추천
Did you call fopen() before you called feof()? I suspect not. At least you didn't put it in your code.
댓글 수: 3
Very Determined
2015년 5월 3일
Yes, I did as fileID = fopen(fullFileName); but didn't want to make it complicated. Here is more :
for RunFolder_counter = 1:3;
if ~isdir(myFolder{RunFolder_counter})
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder{RunFolder_counter});
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder{RunFolder_counter}, '*.log');
logFiles = dir(filePattern);
for k = 1:length(logFiles)
baseFileName = logFiles(k).name;
fullFileName = fullfile(myFolder{RunFolder_counter}, baseFileName);
fileID = fopen(fullFileName);
date_time = textscan(fileID,'Date %s Time %s','HeaderLines',1);
column_headers = textscan(fileID,'%s',41,'delimiter', '\t');
counter =1;
while (~feof(fileID))
[data,position] = textscan(fileID,'%f',82,'delimiter', '\t\t');
real_data{counter,:} = data;
counter = counter + 1;
end
counter = counter - 2;
fclose(fileID);
Image Analyst
2015년 5월 3일
I never use textscan() but when I've seen people use it they don't loop over lines but suck up the whole file in one call. Maybe Star will know - he uses it more than me.
Very Determined
2015년 5월 3일
편집: Very Determined
2015년 5월 3일
Thanks. Looking forward to here from Star.
카테고리
도움말 센터 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!