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개)
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);
Ashan Walpitage
2021년 9월 22일
Try with readtable function
mydata = readtable( file_path )
카테고리
도움말 센터 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!