How can i seperate numbers from strings while using textscan?

I want to store this data in a cell using textscan:
2000,146.557,OE,-300,150
2000,146.625,FOB,0,0
My code is
fidT=fopen('test.txt');
dataT=textscan(fidT,'%d,%f,%s,%d,%d');
But matlab handles "OE,-300,150" as one string. I want matlab to handle it as 1 string, followed by 2 numbers. How can I do that?

 채택된 답변

Stephen23
Stephen23 2017년 1월 19일
편집: Stephen23 2017년 1월 19일
>> str = '2000,146.557,OE,-300,150 2000,146.625,FOB,0,0';
>> textscan(str,'%f%f%s%f%s%f%s%f%f','Delimiter',',')
ans =
Columns 1 through 7
[2000] [146.557] {1x1 cell} [-300] {1x1 cell} [146.625] {1x1 cell}
Columns 8 through 9
[0] [0]
If you edit your question and upload the data file using the paperclip button then I can also show you how to make it work for your file.
Note that the 150 2000 is parsed as one string, because you did not put a comma. Is this a mistake?

댓글 수: 1

Thanks for reply. I already solved it by using this line.
fid=fopen('test.txt');
data=textscan(fid,'%d%f%s%d%d%d%s%s','Delimiter',',');

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

태그

질문:

2017년 1월 19일

댓글:

2017년 2월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by