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

时间秒杀一切 提交于 2020-01-14 03:15:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!