问题将各个变量在MATLAB一类数组的元素分配 [英] Problem with assigning elements of a class array to individual variables in MATLAB
问题描述
这是一个有点重复<的href=\"http://stackoverflow.com/questions/2893356/matlab-easiest-way-to-assign-elements-of-a-vector-to-individual-variables\">this问题,这个问题和<一个href=\"http://stackoverflow.com/questions/2740704/is-there-anything-like-deal-for-normal-matlab-arrays\">this问题,但是这些解决方案不工作,所以我要求我的。
This is a bit of a duplicate of this question, this question, and this question, however those solutions don't work, so I'm asking mine.
我有本地定义类的数组,我想将它分配给多个,单个变量。这种模式不起作用:
I've got an array of locally defined classes and I'd like to assign it to multiple, individual variables. This pattern doesn't work:
%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.
由于临时
是单个细胞,并在一个单元我的2×1阵列,而不是在一个小区与每个我的原始数组中的一个元素的2×1单元阵列。
Because temp
is a single cell, with my 2x1 array in one cell, rather than a 2x1 cell array with one element of each of my original array in one cell.
任何想法?
推荐答案
您应该使用功能的 NUM2CELL ,而不是功能的 MAT2CELL 以阵列的每个元素放在 A
在单元阵列的一个独立单元温度
。
You should use the function NUM2CELL instead of the function MAT2CELL in order to place each element of your array a
in a separate cell of your cell array temp
.
使用 MAT2CELL 只需输入相当于在做 TEMP = {A};
,并在我的版本MATLAB(R2009a)的我居然得到这样的警告:
Using MAT2CELL with just one input is equivalent to doing temp = {a};
, and in my version of MATLAB (R2009a) I actually get this warning:
>> 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
这篇关于问题将各个变量在MATLAB一类数组的元素分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!