Spitting matrix A into other matrices using the last two columns values

조회 수: 1 (최근 30일)
JL
JL 2020년 6월 3일
댓글: JL 2020년 6월 3일
I have a matrix A
A = [1 1 1;
2 1 1;
3 1 1;
4 2 1;
5 2 2;
6 2 2];
And would like to split them into different matrices (up to n) depending on the last two columns being the same
A1 = [1 1 1;
2 1 1];
The 3rd row of matrix A has the same last two columns but because there’s a limit up to 2 row each matrix, it will be on another matrix A2
A2 = [3 1 1];
The rest will be A3 and A4 below
A3 = [4 2 1];
A4 = [5 2 2
6 2 2];

답변 (1개)

KSSV
KSSV 2020년 6월 3일
편집: KSSV 2020년 6월 3일
A = [1 1 1;
2 1 1;
3 1 1;
4 2 1;
5 2 2;
6 2 2];
rowDist = [2 1 1 2] ;
iwant = mat2cell(A,rowDist) ;
Access iwant by iwant{1},iwant{2}...etc...
  댓글 수: 6
KSSV
KSSV 2020년 6월 3일
On what criteria you have come to conclusion of [2 1 1 2]? Is there any criteria?
JL
JL 2020년 6월 3일
I have mentioned it in my question above. (1) last two columns of each rows, need to be put in the same matrix, (2) if theres three rows having the same last two columns, the 3rd one will have to move on to another matrix

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

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by