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 日

0 投票

>> 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 件のコメント

student89
student89 2017 年 2 月 10 日
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