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!