フィルターのクリア

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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by