How can I read a txt file and split its content into a strings array and a data array?
31 ビュー (過去 30 日間)
古いコメントを表示
The txt file has information similar to the one below. A would like to have an array of strings (headerline) and an (N X 4) array of data.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/192599/image.jpeg)
0 件のコメント
回答 (2 件)
Walter Roberson
2018 年 7 月 25 日
編集済み: Walter Roberson
2018 年 7 月 25 日
fid = fopen(filename, 'rt');
headers = string( strsplit( fgetl(fid), ';') );
data = cell2mat( textscan(fid, '%f%f%f%f', 'Delimiter', ';', 'collectoutput', 1) );
fclose(fid);
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!