我该怎么做在MATLAB多重分配? [英] How do I do multiple assignment in MATLAB?
本文介绍了我该怎么做在MATLAB多重分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是一个例子就是我在寻找:
Here's an example of what I'm looking for:
>> foo = [88, 12];
>> [x, y] = foo;
我的期望的像这样算账:
>> x
x =
88
>> y
y =
12
而是我得到这样的错误:
But instead I get errors like:
??? Too many output arguments.
我觉得交易()
可能做到这一点,但它似乎只对细胞的正常工作。
I thought deal()
might do it, but it seems to only work on cells.
>> [x, y] = deal(foo{:});
??? Cell contents reference from a non-cell array object.
我如何解决我的问题?我必须不断地被1和2的索引,如果我想单独对付他们?
How do I solve my problem? Must I constantly index by 1 and 2 if I want to deal with them separately?
推荐答案
您不需要交易
在所有(编辑:Matlab的7.0或更高版本),对于你的榜样,你不需要 mat2cell
;您可以使用 num2cell
没有其他参数:
You don't need deal
at all (edit: for Matlab 7.0 or later) and, for your example, you don't need mat2cell
; you can use num2cell
with no other arguments::
foo = [88, 12];
fooCell = num2cell(foo);
[x y]=fooCell{:}
x =
88
y =
12
如果你想使用交易
某些其他原因,您可以:
If you want to use deal
for some other reason, you can:
foo = [88, 12];
fooCell = num2cell(foo);
[x y]=deal(fooCell{:})
x =
88
y =
12
这篇关于我该怎么做在MATLAB多重分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文