read file with text and numericals
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Johannes Neumann
2019년 11월 15일
편집: Johannes Neumann
2019년 11월 15일
댓글 수: 1
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 Exchange에서 Text Data Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!