auto split matrix with text and numbers into other matrices (up to n)

2 vues (au cours des 30 derniers jours)
JL
JL le 3 Juin 2020
Commenté : JL le 3 Juin 2020
Matrix A
A = [Aaa Bbb Ccc 1 1 1
Ddd Eee Fee 1 1 1
Ggg Hhh Iii 1 1 2
Jjj Kkk Lll 1 1 2
Mmm Nnn Ooo 2 2 3
Ppp Qqq Rrr 2 2 3];
auto split into other matrices B,C,D (potentially all the way to N) based on the last column
B = [Aaa Bbb Ccc 1 1 1
Ddd Eee Fee 1 1 1];
C = [Ggg Hhh Iii 1 1 2
Jjj Kkk Lll 1 1 2];
D = [Mmm Nnn Ooo 2 2 3
Ppp Qqq Rrr 2 2 3];

Réponses (1)

KSSV
KSSV le 3 Juin 2020
C = A(:,end) ;
[c,ia,ib] = unique(C) ;
N = length(c) ;
iwant = cell(N,1) ;
for i = 1:N
iwant{i} = A(ib==i,:) ;
end
iwant
  6 commentaires
KSSV
KSSV le 3 Juin 2020
The how do you think strings and numbers will form a matrix? You need to save them either in table or cells.
JL
JL le 3 Juin 2020
How do i do that, please?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by