![]() |
在MATLAB中将类数组的元素分配给各个变量的问题
这是[URL="https://stackoverflow.com/questions/2893356/matlab-easiest-way-to-assign-elements-of-a-vector-to-individual-variables"]该问题[/URL] , [URL="https://stackoverflow.com/questions/2337126/multiple-assignment-in-matlab"]该问题[/URL]和[URL="https://stackoverflow.com/questions/2740704/is-there-anything-like-deal-for-normal-matlab-arrays"]该问题[/URL]的重复部分,但是这些解决方案不起作用,所以我要问我。
我有一组本地定义的类,我想将其分配给多个单独的变量。此模式不起作用: %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单元格数组,而每个原始数组中的每个元素只有一个元素。 有任何想法吗? [B]回答:[/B] 您应该使用函数[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/num2cell.html"]NUM2CELL[/URL]而不是函数[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/mat2cell.html"]MAT2CELL[/URL] ,以便将数组a每个元素放置在单元格数组temp的单独单元格中。 仅使用一个输入使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/mat2cell.html"]MAT2CELL[/URL]等同于执行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 [url=https://stackoverflow.com/questions/3038152]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 23:35。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.