automatically create a group of same elements from an array
3 ビュー (過去 30 日間)
古いコメントを表示
hello, i have a question about how to automatically group same elements of an array. Example: A=(3,3,3,2,1,4,5,5)
i want to group it into: Group1=(1) Group2=(2) Group3=(3,3,3) Group4=(4) Group5=(5,5)
but sometimes, the elements can be varied and it depends on the calculation. So the number of groups cannot be determined manually. So may i ask your idea, how to make the group automatically based on A ,using for loop?
2 件のコメント
Geoff Hayes
2018 年 8 月 29 日
Surya - please clarify what you mean by the elements can be varied and it depends on the calculation. Also, are you elements always integers?
回答 (1 件)
KL
2018 年 8 月 29 日
try this,
result =mat2cell(sort(A),1, histcounts(findgroups(A))) %A is your array
Output is a cell array where you have groups separated into columns.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!