'Matlab matrix to cell
I'm trying to avoid loops in Matlab. How can I do the following matrix to cell conversion vectorized?
m1 = ones(10, 2);
i = [1:10]';
m2 = [i i];
c = cell(10, 2);
for i=1:10
c{i, 1} = m1(i, :);
c{i, 2} = m2(i, :);
end
Solution 1:[1]
As mentioned by @beaker mat2cell() is the function to use here...this should work:
c = mat2cell([m1,m2],ones(10,1),[2,2])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | liamcsmith |
