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 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!