I needs to read the attached text file using MATLAB and split the columns by coma (,)

댓글 수: 2

Stephen23
Stephen23 2015년 11월 5일
편집: Stephen23 2015년 11월 5일
There is no file attached. You need to press the paperclip button, then both the Choose file and Attach file buttons.
Prabodha Wijerathne
Prabodha Wijerathne 2015년 11월 5일
Sorry about that. I just attached the file

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephen23
Stephen23 2015년 11월 5일
편집: Stephen23 2015년 11월 5일

1 개 추천

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}.

카테고리

도움말 센터File Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

질문:

2015년 11월 5일

편집:

2015년 11월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by