merlin2011
merlin2011

Reputation: 75545

How do I consume multiple outputs of `textscan` function in a single line?

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.

Upvotes: 1

Views: 389

Answers (1)

Rasman
Rasman

Reputation: 5359

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 {:});

Upvotes: 3

Related Questions