auto split matrix into other matrices (up to n)

Matrix A
A = [1 55 14 1 1 1
2 55 14 1 1 1
5 35 13 1 1 2
6 35 12 1 1 2
7 35 11 2 2 3
8 35 11 2 2 3;
auto split into other matrices B,C,D (potentially all the way to N) based on the last column
B = [1 55 14 1 1 1
2 55 14 1 1 1];
C = [5 35 13 1 1 2
6 35 12 1 1 2];
D = [7 35 11 2 2 3
8 35 11 2 2 3];

 채택된 답변

KSSV
KSSV 2020년 5월 28일

0 개 추천

A = [1 55 14 1 1 1
2 55 14 1 1 1
5 35 13 1 1 2
6 35 12 1 1 2
7 35 11 2 2 3
8 35 11 2 2 3];
C = A(:,end) ;
[c,ia,ib] = unique(A(:,end)) ;
N = length(c) ;
iwant = cell(N,1) ;
for i = 1:N
iwant{i} = A(ib==i,:) ;
end

댓글 수: 3

JL
JL 2020년 5월 28일
it doesn't provide me this result.
B = [1 55 14 1 1 1
2 55 14 1 1 1];
C = [5 35 13 1 1 2
6 35 12 1 1 2];
D = [7 35 11 2 2 3
8 35 11 2 2 3];
KSSV
KSSV 2020년 5월 28일
You have what you want....iwant{1}, iwant{2}, iwant{3}
JL
JL 2020년 5월 28일
thats true! thanks :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

질문:

JL
2020년 5월 28일

댓글:

JL
2020년 5월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by