% David E. Haddad % 07/2008 % This script counts the number of lines in a text file. It is designed % to exclude blank lines or commented lines when doing the count. % IMPORTANT NOTE: This script will include the header in the line count if % the input file has a header. % here we go... % CHANGE THIS TO YOUR FILE'S NAME AND EXTENSION: fid = fopen('input_filename.txt', 'r'); count = 0; while ~feof(fid) line = fgetl(fid); if isempty(line) | strncmp(line, '%', 1) continue % this statement advances the loop to the next line in the text file % without counting blank lines or commented lines. end count = count + 1; end number_of_lines = count