Read and sort data in a text file
5 views (last 30 days)
Show older comments
Djamil Boulahbal
on 16 Sep 2020
Edited: Djamil Boulahbal
on 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 Comments
Accepted Answer
Mohammad Sami
on 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 Comments
More Answers (2)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!