Filter löschen
Filter löschen

read file with text and numericals

1 Ansicht (letzte 30 Tage)
shravani nethi
shravani nethi am 15 Nov. 2019
Kommentiert: Walter Roberson am 21 Dez. 2019
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

Akzeptierte Antwort

Johannes Neumann
Johannes Neumann am 15 Nov. 2019
Bearbeitet: Johannes Neumann am 15 Nov. 2019
  1 Kommentar
Walter Roberson
Walter Roberson am 21 Dez. 2019
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by