How to group variables in a same cluster ?

1 回表示 (過去 30 日間)
Pradya Panyainkaew
Pradya Panyainkaew 2018 年 1 月 8 日
if I have
A=[1 2; 2 4; 3 4; 4 1; 5 1; 6 4; 7 4; 8 2; 9 1; 10 1]
where 1st column represents customer ID and 2nd column shows Clustering Number. How can I group customer ID into a same cluster such as
cluster1=[4 5 9 10], cluster2=[1,8], cluster3=[ ], cluster4=[2,3,6,7]

採用された回答

ANKUR KUMAR
ANKUR KUMAR 2018 年 1 月 8 日
編集済み: ANKUR KUMAR 2018 年 1 月 8 日
A=[1 2; 2 4; 3 4; 4 1; 5 1; 6 4; 7 4; 8 2; 9 1; 10 1]
id=unique(A(:,2))
for ii=1:length(id)
iid{ii}=A(find(A(:,2)==id(ii)),1)
end
you can see the outputs just by entering iid{1}
  3 件のコメント
ANKUR KUMAR
ANKUR KUMAR 2018 年 1 月 8 日
Sir, I am just a student. That was my mistake. Sorry for this.
Pradya Panyainkaew
Pradya Panyainkaew 2018 年 1 月 8 日

It's fine. Don't worry. I'm a rookie also. It's not your fault. Let's share.

サインインしてコメントする。

その他の回答 (1 件)

Guillaume
Guillaume 2018 年 1 月 8 日
Assuming your clustering numbers are all strictly positive integers:
accumarray(A(:, 2), A(:, 1), [], @(custs) {custs})
  1 件のコメント
Pradya Panyainkaew
Pradya Panyainkaew 2018 年 1 月 8 日
Thank you very much. it is excellent code.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by