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

2 次查看(过去 30 天)
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];

回答(1 个)

KSSV
KSSV 2020-6-3
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 个评论
KSSV
KSSV 2020-6-3
The how do you think strings and numbers will form a matrix? You need to save them either in table or cells.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by