Read text file using MATLAB
4 次查看(过去 30 天)
显示 更早的评论
I needs to read the attached text file using MATLAB and split the columns by coma (,)
2 个评论
回答(1 个)
Stephen23
2015-11-5
编辑:Stephen23
2015-11-5
fid = fopen(filename,'rt');
C = textscan(fid,format,'Delimiter',',');
fclose(fid);
Read the textscan documentation to know how to specify the format string, OR please supply us with your sample file and we can show you how the format string can be defined.
EDIT: using the newly uploaded datafile:
fnm = 'LogFile_Test.txt';
fmt = '%*s%s%*s%f%*s%f%*s%f%*s%f%*s%f%*s%f;\n';
fid = fopen(fnm,'rt');
C = textscan(fid,fmt,'Delimiter',{',',':'});
fclose(fid);
D = horzcat(C{2:end});
This code reads the numeric columns of the file into a numeric matrix D. The first data column contains multiple '-' characters, and is imported as a string in C{1}.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!