如何在一行中使用`textscan`函数的多个输出? [英] How do I consume multiple outputs of `textscan` function in a single line?

查看:121
本文介绍了如何在一行中使用`textscan`函数的多个输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下字符串:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆