问题
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:
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 {:});
来源:https://stackoverflow.com/questions/16126438/how-do-i-consume-multiple-outputs-of-textscan-function-in-a-single-line