如何在一行中使用`textscan`函数的多个输出? [英] How do I consume multiple outputs of `textscan` function in a single line?
问题描述
假设我有以下字符串:
s ='Foo 1.000 3.000 3.554'
s = 'Foo 1.000 3.000 3.554'
我想用textscan
函数按如下方式阅读它.
I would like to read it with the textscan
function as follows.
[name x y z] = textscan(s,'%s%f%f%f')
[name x y z] = textscan(s, '%s %f %f %f')
但是,当我这样做时,总是会出现Too many output arguments
错误.
However, when I do this, I always get the Too many output arguments
error.
我认为这与textscan
输出一个单元格数组有关,但是我找不到解决该问题和所需效果的方法.
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.
推荐答案
您将需要两行来完成所需的操作.首先,将所需的值转换为虚拟变量,然后使用deal
分配数据:
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 {:});
这篇关于如何在一行中使用`textscan`函数的多个输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!