这有点重复 this question , this question ,和this question ,但是这些解决方案不起作用,所以我问我的。
我有一个本地定义的类数组,我想将其分配给多个单独的变量。这种模式不起作用:
%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.
因为 temp
是一个单元格,我的 2x1 数组位于一个单元格中,而不是 2x1 单元格数组,其中每个原始数组的一个元素位于一个单元格中。
有什么想法吗?
最佳答案
您应该使用函数 NUM2CELL而不是函数MAT2CELL以便将数组 a
的每个元素放入元胞数组 temp
的单独单元格中。
使用MAT2CELL仅使用一个输入相当于执行 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
关于arrays - 在 MATLAB 中将类数组的元素分配给各个变量时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3038152/