~feof doesnt woek properly, how to fix the problem.
Show older comments
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 Comments
Guillaume
on 29 Apr 2015
Can you attach a file that replicate the problem?
Very Determined
on 3 May 2015
Edited: Very Determined
on 3 May 2015
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.
Accepted Answer
More Answers (1)
Image Analyst
on 3 May 2015
0 votes
Did you call fopen() before you called feof()? I suspect not. At least you didn't put it in your code.
3 Comments
Very Determined
on 3 May 2015
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
on 3 May 2015
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
on 3 May 2015
Edited: Very Determined
on 3 May 2015
Thanks. Looking forward to here from Star.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!