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!