Hi
Right now I have a simple text file with a single coordinate point (0.2, 0.8, 0.5) and I would like to read it into MATLAB so that I have 3 variables x = 0.2, y = 0.8, z = 0.5.
importdata will only give me 1 value, which looks like (0.2, 0.8, 0.5) and when I tried using textscan(fileID, '%d'), I just get one value which looks like [].
What do I need to put, please help! Thanks

2 件のコメント

Walter Roberson
Walter Roberson 2015 年 9 月 17 日
Please show us an exact copy of one of the text files.
Mallard
Mallard 2015 年 9 月 17 日
Well it just has this in the top left hand corner and that is all.
(0.3, 2.8, 0.2)

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

回答 (1 件)

dpb
dpb 2015 年 9 月 17 日
編集済み: dpb 2015 年 9 月 19 日

0 投票

"...I tried using textscan(fileID, '%d')"
(0.2, 0.8, 0.5) values are floating point, not integers so %d won't work and you didn't account for the nonnumeric paren's nor the delimiter in the format string...
>> s='(0.2, 0.8, 0.5)'
s =
(0.2, 0.8, 0.5)
>> textscan(s,'(%f%f%f)','delimiter',',','collectoutput',1)
ans =
[1x3 double]
>> cell2mat(textscan(s,'(%f%f%f)','delimiter',',','collectoutput',1))
ans =
0.2000 0.8000 0.5000
>>
NB the collectoutput parameter as well as delimiter. I also went ahead and wrapped the call w/ cell2mat to get a "regular" array rather than a cell array that is returned by textscan

質問済み:

2015 年 9 月 17 日

編集済み:

dpb
2015 年 9 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by