MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   普通的MATLAB数组是否有诸如deal()之类的东西? (https://www.labfans.com/bbs/showthread.php?t=23373)

poster 2019-12-10 20:41

普通的MATLAB数组是否有诸如deal()之类的东西?
 
[INDENT] [B]可能重复:[/B]
[URL="https://stackoverflow.com/questions/2337126/how-do-i-do-multiple-assignment-in-matlab"]如何在MATLAB中进行多重分配?[/URL]

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

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

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

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



[B]回答:[/B]

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

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



[url=https://stackoverflow.com/questions/2740704]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:16

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.