How can I read a txt file and split its content into a strings array and a data array?
Afficher commentaires plus anciens
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.

Réponses (2)
Walter Roberson
le 25 Juil 2018
Modifié(e) : Walter Roberson
le 25 Juil 2018
fid = fopen(filename, 'rt');
headers = string( strsplit( fgetl(fid), ';') );
data = cell2mat( textscan(fid, '%f%f%f%f', 'Delimiter', ';', 'collectoutput', 1) );
fclose(fid);
1 commentaire
Ernesto Momox Beristain
le 26 Juil 2018
Ashan Walpitage
le 22 Sep 2021
Try with readtable function
mydata = readtable( file_path )
Catégories
En savoir plus sur Low-Level File I/O dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!