Is there a way in Matlab to determine the number of lines in a file without looping through each line?

后端 未结 5 1671
無奈伤痛
無奈伤痛 2020-12-05 00:57

Obviously one could loop through a file using fgetl or similar function and increment a counter, but is there a way to determine the number of lines in a file without

5条回答
  •  爱一瞬间的悲伤
    2020-12-05 01:16

    You can read the entire file at once, and then count how many lines you've read.

    fid = fopen('yourFile.ext');
    
    allText = textscan(fid,'%s','delimiter','\n');
    
    numberOfLines = length(allText{1});
    
    fclose(fid)
    

提交回复
热议问题