这有点重复这个问题 https://stackoverflow.com/questions/2893356/matlab-easiest-way-to-assign-elements-of-a-vector-to-individual-variables, 这个问题 https://stackoverflow.com/questions/2337126/multiple-assignment-in-matlab, and 这个问题 https://stackoverflow.com/questions/2740704/is-there-anything-like-deal-for-normal-matlab-arrays,但是这些解决方案不起作用,所以我问我的。
我有一组本地定义的类,我想将其分配给多个单独的变量。这种模式不起作用:
%a is 2x1 of MyClass
temp = mat2cell(a);
[x,y] = temp{:};
%throws:
??? Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
Because temp
是一个单元格,我的 2x1 数组位于一个单元格中,而不是 2x1 单元格数组,其中每个原始数组的一个元素位于一个单元格中。
有任何想法吗?
你应该使用该功能NUM2CELL http://www.mathworks.com/access/helpdesk/help/techdoc/ref/num2cell.html而不是函数MAT2CELL http://www.mathworks.com/access/helpdesk/help/techdoc/ref/mat2cell.html为了放置数组的每个元素a
在元胞数组的单独元胞中temp
.
Using MAT2CELL http://www.mathworks.com/access/helpdesk/help/techdoc/ref/mat2cell.html仅使用一个输入相当于执行temp = {a};
,在我的 MATLAB (R2009a) 版本中,我实际上收到了此警告:
>> temp = mat2cell(a);
Warning: Single input behavior is obsolete and will be removed in a
future release of MATLAB. Use C={X} instead.
> In mat2cell at 54
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)