How to skip lines in the middle of a text file when reading a text file?
1 次查看(过去 30 天)
显示 更早的评论
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
<<

>>
.

0 个评论
回答(1 个)
Walter Roberson
2018-8-22
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!