Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
MS
MS le 16 Déc 2022
Réponse apportée : Matt J le 16 Déc 2022
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

Réponse acceptée

Matt J
Matt J le 16 Déc 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

Plus de réponses (1)

Matt J
Matt J le 16 Déc 2022
Modifié(e) : Matt J le 16 Déc 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 commentaire
MS
MS le 16 Déc 2022
Modifié(e) : MS le 16 Déc 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by