Filter löschen
Filter löschen

textscan (read data from second and fourth line)

1 Ansicht (letzte 30 Tage)
Haris Hameed
Haris Hameed am 14 Mai 2012
i am having some trouble using textscan
i have data in input file as
AAA BBB CCC DDD
10 20 30 40
EEE FFF
40 50
how to read this data
i can read data if it is only in the first line of input file but having trouble it data is in multiple line
  2 Kommentare
Walter Roberson
Walter Roberson am 14 Mai 2012
Do you know the exact number of values on the 2nd and 4th line?
Haris Hameed
Haris Hameed am 14 Mai 2012
yes 4 values in second line and 2 in fourth line
line one and line three contains the parameter name

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 14 Mai 2012
L2cell = textscan(fid, '%f%f%f%f', 1, 'HeaderLines', 1, 'CollectOutput', 1);
L4cell = textscan(fid, '%f%f', 1, 'HeaderLines', 1, 'CollectOutput', 1);
  8 Kommentare
Thomas
Thomas am 14 Mai 2012
Walter, you do not need to reset to the beginning of the file at-least not in 2012a. The following works just fine.. Though it might not be the optimal way of doing this.. :)
fid=fopen('input1.dat','r');
L2cell = textscan(fid, '%f%f%f%f', 1, 'HeaderLines', 1);
L4cell = textscan(fid, '%f%f', 1, 'HeaderLines', 3);
L2cell{:}
L4cell{:}
Daimien Burks
Daimien Burks am 14 Mai 2012
Don't mean to steal the thread, but would this work on columns as well? Like get AAA/10 and CCC/30?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by