How can I read a txt file and split its content into a strings array and a data array?

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.

回答(2 个)

fid = fopen(filename, 'rt');
headers = string( strsplit( fgetl(fid), ';') );
data = cell2mat( textscan(fid, '%f%f%f%f', 'Delimiter', ';', 'collectoutput', 1) );
fclose(fid);

类别

帮助中心File Exchange 中查找有关 Cell Arrays 的更多信息

产品

版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by