count = 0;
while true
if ~ischar( fgetl(fid) ); break; end
count = count + 1;
end
fclose(fid)
title(sprintf('lines in file = %d', count));
Note that feof(fid) never predicts end of file. feof() is never true unless you have already tried to read after the end of file, so even with a completely empty file, feof() would not immediately be true.
You can tell you have reached end of file when fgetl() returns something that is not a character.
Best Answer