read file with text and numericals

2 ビュー (過去 30 日間)
shravani nethi
shravani nethi 2019 年 11 月 15 日
コメント済み: Walter Roberson 2019 年 12 月 21 日
I have a file as follows
it contains 3 text lines at starting, data with 2 columns for every 3 lines which have 5 columns in each line.
How to read it in matlab?
example:
# this is line 1
# this is line 2
#this is line 3
10 25
1 14.34 25.98 576.6779 34.79080
2 78.90 45.980 345.980 4534.809
3 70.39 234.32 34.456 456.00
20 25
1 31.6626 16.4479 6.9191 55.0296
2 149.629 105.448 231.137 486.214
3 0.000261389 44.6379 271.636 316.274
30 25
1 35.3791 12.0603 6.48611 53.9255
2 146.574 111.14 248.954 506.668
3 1.1585 64.3987 348.685 414.242
I need to separate line with 2 columns and lines with 5 columns

採用された回答

Johannes Neumann
Johannes Neumann 2019 年 11 月 15 日
編集済み: Johannes Neumann 2019 年 11 月 15 日
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 12 月 21 日
In particular, fopen() . fread() 3 lines and discard them. Then loop while ~feof()
cell2mat(textscan(fid, '%f%f', 1)) %to get the pair of numbers
cell2mat(textscan(fid, '%f%f%f%f%f', 3)) %to read the 5 columns
end of loop
each round storing the data somewhere appropriate
Though for your purposes, it might be easier to just loop using fscanf() as appropriate

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by