I assume that you are working with text files since you mentioned searching for the number of lines. Here is one solution:
fid = fopen('your_file.dat','rt'); nLines = 0; while (fgets(fid) ~= -1), nLines = nLines+1; end fclose(fid);
It uses FGETS to read each line, counting the number of lines it reads. Note that the data from the file is never saved in the workspace, it is just used in the conditional check of the while loop.
source share