How to skip lines in the middle of a text file when reading a text file?

1 view (last 30 days)
I am trying to use matlab to do post data analysis. It is a text file that contains 128100*441 lines of coordinates (x,y,z). 441 represents timestep. The problem is that the file contains two lines of headerlines every timestep, meaning there are 441*2 lines I should skip. I know how to skip first two headerlines using textscan(...'headerlines',2) but I don't know how to deal with rest of them. Besides, I also need to get the average coordinate every 2562 coordinate(because every 2562 coordinates is on one body, average coordinate represents mass center, there are 50 bodies in one timestep because 50*2562=128100). I want to use a loop but I don't know how to indicate the line number of those lines that I want to skip
<<
>>
.

Answers (1)

Walter Roberson
Walter Roberson on 22 Aug 2018
With textscan you should be able to use 'CommentStyle', 'Atoms' to skip the Atoms line.
However, the line before that is a partial line. It looks like it might be an atom count. There are various ways you could handle that, but you should consider changing your textscan to include the number of lines to read directly after the format string, and reading in blocks.

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products


Release

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!