Read and sort data in a text file
7 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Mohammad Sami
2020 年 9 月 16 日
You can use the readtable function. It will autodetect the variable types.
tab = readtable('myfile.txt');
tab = sortrows(tab,{'col1' 'col2'});
0 件のコメント
その他の回答 (2 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!