필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
MS
MS 2022년 12월 16일
답변: Matt J 2022년 12월 16일
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

채택된 답변

Matt J
Matt J 2022년 12월 16일
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

추가 답변 (1개)

Matt J
Matt J 2022년 12월 16일
편집: Matt J 2022년 12월 16일
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
MS
MS 2022년 12월 16일
편집: MS 2022년 12월 16일
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.

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

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by