how to split 6x4 double based on first columns values into three [2X4]?

1 visualizzazione (ultimi 30 giorni)
4 1 2 3
4 5 6 7
5 1 2 3
5 4 5 6 ====>> [4 1 2 3 [ 5 1 2 3 [6 1 2 3
5 4 5 6
5 4 5 6 4 5 6 7] 5 4 5 6] 6 4 5 6]
6 1 2 3
6 4 5 6

Risposta accettata

Matt J
Matt J il 16 Dic 2022
A=[4 1 2 3
4 5 6 7
5 1 2 3
5 4 5 6
5 4 5 6
5 4 5 6
6 1 2 3
6 4 5 6];
A=unique(A,'rows');
Acell=splitapply(@(x){x}, A,findgroups(A(:,1)));
Acell{:}
ans = 2×4
4 1 2 3 4 5 6 7
ans = 2×4
5 1 2 3 5 4 5 6
ans = 2×4
6 1 2 3 6 4 5 6

Più risposte (1)

Matt J
Matt J il 16 Dic 2022
Modificato: Matt J il 16 Dic 2022
A=randi(9,6,4)
A = 6×4
6 1 9 7 8 5 8 9 9 7 9 9 6 4 1 4 6 7 7 9 3 8 1 2
Acell=mat2tiles(A,[2,4]); %get mat2tiles from https://www.mathworks.com/matlabcentral/fileexchange/35085-mat2tiles-divide-array-into-equal-sized-sub-arrays
Acell{:}
ans = 2×4
6 1 9 7 8 5 8 9
ans = 2×4
9 7 9 9 6 4 1 4
ans = 2×4
6 7 7 9 3 8 1 2
  1 Commento
MS
MS il 16 Dic 2022
Modificato: MS il 16 Dic 2022
Thanks @Matt J sorry for the mis commmunciation. if you see the three splitted/grouped matrices are based on the fitst column values. I mean, it should be grouped based on the first column values such as 4, 5, 6.
All matrices should be grouped based on the first column values. 1, all matcies with 4 should be sperate matrix 2, all matrix with 5 should be sperate matrix 3, all matcies with 6should be sperate matrix etc.,
my matrix is not random.

Accedi per commentare.

Categorie

Scopri di più su Resizing and Reshaping Matrices 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