How can I read a txt file and split its content into a strings array and a data array?
31 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ernesto Momox Beristain
el 25 de Jul. de 2018
Respondida: Ashan Walpitage
el 22 de Sept. de 2021
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 comentarios
Respuestas (2)
Walter Roberson
el 25 de Jul. de 2018
Editada: Walter Roberson
el 25 de Jul. de 2018
fid = fopen(filename, 'rt');
headers = string( strsplit( fgetl(fid), ';') );
data = cell2mat( textscan(fid, '%f%f%f%f', 'Delimiter', ';', 'collectoutput', 1) );
fclose(fid);
Ashan Walpitage
el 22 de Sept. de 2021
Try with readtable function
mydata = readtable( file_path )
0 comentarios
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!