How do I consume multiple outputs of `textscan` fu

2019-06-06 01:40发布

Suppose I have the following string:

s = 'Foo 1.000 3.000 3.554'

I would like to read it with the textscan function as follows.

[name x y z] = textscan(s, '%s %f %f %f')

However, when I do this, I always get the Too many output arguments error.

I think it has to do with the fact that textscan outputs a cell array, but I could not discover how to work around this problem and the desired effect.

1条回答
叼着烟拽天下
2楼-- · 2019-06-06 01:45

You'll need two lines to do what you want. First you get the desired valued into a dummy variable, then distribute the data with deal:

dummy = textscan(s, '%s %f %f %f');
[a,b,c,d] = deal(dummy {:});
查看更多
登录 后发表回答