MATLAB: how to read every Nth line of a text file?

前端 未结 2 758
予麋鹿
予麋鹿 2021-01-03 11:41

I have some data that\'s formatted as follows:

dtau     E_av        variance    N_sims      Time
0.001   0.497951    0.000211625 25      Sun Apr  3 18:18:12          


        
2条回答
  •  渐次进展
    2021-01-03 12:09

    fid = fopen('data.text')
    while ~feof(fid)
      results = textscan(fid, '%f %f %f %f', 1,'headerlines',1);
      //Processing...
    
      for i = 1:2
        fgets(fid)
      end
    end
    

    fgets reads until the end of a line, and returns the text on that line. So, just call it twice to skip two lines (discarding the return value of the function).

提交回复
热议问题