How can I divide a matrix by its columns ?

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

the cyclist
the cyclist il 23 Apr 2014
Modificato: the cyclist il 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.

Più risposte (0)

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by