How to put text into an array

Hi all,
I have a big text right now and I wish to put every line as an array... could someone help?
201403 0.000 8.333 0.00 0.00
So this is one of the lines of my text, and I wish to sort it as an array like
2014 03 0.000 8.333 0.00 0.00
Can anybody help please?
Thanks!

1 件のコメント

per isakson
per isakson 2014 年 10 月 24 日
編集済み: per isakson 2014 年 10 月 24 日
I don't understand your question. What do the other lines look like and what should happen to them?

サインインしてコメントする。

 採用された回答

per isakson
per isakson 2014 年 10 月 24 日
編集済み: per isakson 2014 年 10 月 24 日

0 投票

Hint:
>> str = '201403 0.000 8.333 0.00 0.00';
>> cac = textscan( str, '%4f%2f%f%f%f%f', 'CollectOutput', true )
cac =
[1x6 double]
>> cac{:}
ans =
1.0e+03 *
2.0140 0.0030 0 0.0083 0 0

4 件のコメント

mt
mt 2014 年 10 月 24 日
Thanks, but I have it as a text file, and I would have to need it as an m file that could do it for every line...
per isakson
per isakson 2014 年 10 月 24 日
編集済み: per isakson 2014 年 10 月 24 日
Did you read the on-line help on &nbsp textscan? &nbsp It should be obvious how to use &nbsp textscan &nbsp with a file. I assumed that the format-specifier was the tricky part.
See my comment to your question.
mt
mt 2014 年 10 月 27 日
I'm trying to make a loop statement for this one. All the other lines are on these formats as well.
Image Analyst
Image Analyst 2014 年 10 月 27 日
I don't understand the second sentence. What do you mean by "on these formats"? Just call fopen(), have your loop with textscan() inside, then call fclose(). What's the problem you are having? Are we supposed to know what your code is? If so, you'll have to post it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeText Data Preparation についてさらに検索

タグ

質問済み:

mt
2014 年 10 月 24 日

コメント済み:

2014 年 10 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by