arrays - 在 MATLAB 中将类数组的元素分配给各个变量时出现问题

标签 arrays matlab variables variable-assignment

这有点重复 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/

相关文章:

从 CSV 数据构建 C 数组

matlab - 在两个序列的匹配部分之间画线

php - 在 PHP 中的类上使用可变变量 (CodeIgniter)

javascript - 具有成员名称的唯一数组

arrays - Python-组合2个具有相同尺寸的掩码数组

javascript - AngularJS 将数组添加到 json 表单对象

matlab - 我可以强制 visdiff 显示超过前 2000 个字节吗?

c - mex 代码在新的 matlab 版本/架构上崩溃

python - 复制的变量改变了原来的?

variables - textarea的Angular2 maxLength作为变量