How can I divide a matrix by its columns ?

2 views (last 30 days)
Hi,
for example:
[ 1 35 37 29 312
1 321 421 2 34
1 329 412 32 54
.
.
.
4 421 348 48 445
4 48 49 41 394 ]
Can I segregate this matrix in small matrix based on the first column ?
Example:
A = [ 1 35 37 29 312
1 321 421 2 34
1 329 412 32 54]
B =...
C =...
D = [ 4 421 348 48 445
4 48 49 41 394 ]
Andre

Accepted Answer

the cyclist
the cyclist on 23 Apr 2014
Edited: the cyclist on 23 Apr 2014
Yes, use the accepted answer from Azzi that is posted here. Just choose the 1st column instead of the 4th column.
Namely, if your original matrix is called A, then
[ii,jj,kk] = unique(A(:,1))
out = accumarray(kk,1:numel(kk),[],@(x) {A(x,:)})
celldisp(out)
You will see that "out" is a cell array, where each cell has one of the smaller matrices you want.

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!