how to count the number of lines of an external txt file
43 views (last 30 days)
Davide Masiello on 2 May 2022
Not sure if there is a better way, but this will work
fid = fopen('a.txt','r');
n = 0;
n = n+1;
Rik on 2 May 2022
The problem with your question is that it lacks a definition of line. If your file ends with char(10) or char(13) does that signify a new line (meaning you have a trailing empty line)?
This is the choice that my readfile function makes. If you use R2020b or later you will be able to use the builtin readlines function. For older releases (or GNU Octave) you will need to use readfile.