How can I divide a matrix by its columns ?

1 Ansicht (letzte 30 Tage)
Andre
Andre am 23 Apr. 2014
Bearbeitet: the cyclist am 23 Apr. 2014
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

Akzeptierte Antwort

the cyclist
the cyclist am 23 Apr. 2014
Bearbeitet: the cyclist am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by