问题
Possible Duplicate:
How do I do multiple assignment in MATLAB?
When dealing with cell arrays, I can use the deal()
function to assign cells to output variables, such as:
[a, b, c] = deal(myCell{:});
or just:
[a, b, c] = myCell{:};
I would like to do the same thing for a simple array, such as:
myArray = [1, 2, 3];
[a, b, c] = deal(myArray(:));
But this doesn't work. What's the alternative?
回答1:
One option is to convert your array to a cell array first using NUM2CELL:
myArray = [1, 2, 3];
cArray = num2cell(myArray);
[a, b, c] = cArray{:};
As you note, you don't even need to use DEAL to distribute the cell contents.
回答2:
Not terribly pretty, but:
myArray = 1:3;
c = arrayfun(@(x) x, myArray , 'UniformOutput', false);
c{:}
来源:https://stackoverflow.com/questions/2740704/is-there-anything-like-deal-for-normal-matlab-arrays