登录论坛

查看完整版本 : 普通的MATLAB数组是否有诸如deal()之类的东西?


poster
2019-12-10, 20:41
可能重复:
如何在MATLAB中进行多重分配? (https://stackoverflow.com/questions/2337126/how-do-i-do-multiple-assignment-in-matlab)

处理单元格数组时,可以使用deal()函数将单元格分配给输出变量,例如:

[a, b, c] = deal(myCell{:}); 要不就:

[a, b, c] = myCell{:}; 我想对一个简单的数组做同样的事情,例如:

myArray = [1, 2, 3]; [a, b, c] = deal(myArray(:)); 但这是行不通的。有什么选择?



回答:

一种选择是先使用NUM2CELL (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/num2cell.html)将数组转换为单元格数组:

myArray = [1, 2, 3]; cArray = num2cell(myArray); [a, b, c] = cArray{:}; 如您所述,您甚至不需要使用DEAL (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/deal.html)分发单元格内容。



更多&回答... (https://stackoverflow.com/questions/2740704)