Read and sort data in a text file
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Djamil Boulahbal
am 16 Sep. 2020
Bearbeitet: Djamil Boulahbal
am 17 Sep. 2020
Greetings,
I have a text/ascii file that looks like below. The first line contains the variables names, and all lines beyond the first contain a mix of numerical and string values. The data is not stored in any specifc/ascending/descending order. What I'd like to do is load all the data into arrays (or structures?) for further manipulation/processing. All variables (beyond the first line) are separated by commas.
I've tried the FID=fopen(...) and then read one line at a time, but that's painfully slow as some of the data files are rather large.
X, Y1, Y2, Y3, Txt1, Txt2, Slope
22,17,31.5,Positive,False,-1
24,11,42.5,Flat,False,-1
17,13,33.0,Flat,True,1
...
0 Kommentare
Akzeptierte Antwort
Mohammad Sami
am 16 Sep. 2020
You can use the readtable function. It will autodetect the variable types.
tab = readtable('myfile.txt');
tab = sortrows(tab,{'col1' 'col2'});
0 Kommentare
Weitere Antworten (2)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!