Clustering data from index

Good morning, I have a matrix like this
ID =
10032 10033
10140 10141
10604 10607
10610 10611
10615 10626
11199 11201
11200 11203
11279 11365
11283 11380
11605 11606
11635 11972
1168 1169
11 382
11 505
11 617
11 761
11 975
975 1320
3000 617
And I want to get all the families for which a same shared number is available for example a family will contain all these couples:
family = [11 382;
11 505;
11 617;
11 761;
11 975;
975 1320;
3000 617]
Do you have any idea about how to cluster this data?
Thanks in advance!

回答 (2 件)

KSSV
KSSV 2016 年 9 月 16 日

0 投票

k = mode(ID(:,1)); % Gets most frequent number
idx = find(ID(:,1)==k) ; % get the indices where k=11 is
iwant = ID(idx,:)

1 件のコメント

Piero Poli
Piero Poli 2016 年 9 月 16 日
編集済み: Piero Poli 2016 年 9 月 16 日
Thanks, however I would like to iterate this process to get all possible families. For examples some families will have just a couple of index (e.g. one line of ID). Any suggestions?
Also, you code is not finding the last two couples of the family one:
975 1320
3000 617
Thank you

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

Andrei Bobrov
Andrei Bobrov 2016 年 9 月 16 日

0 投票

[a,~,c] = unique(ID);
out = ID(any(ismember(ID,a(accumarray(c,1) > 1)),2),:);

2 件のコメント

Piero Poli
Piero Poli 2016 年 9 月 16 日
Thank you Andrei, unfortunately this lines are not providing the output. I was looking for a way to come out with group of families all sharing at the same index, just as show in the family matrix in my question. At the end I would like to have N families.
Thank you
Andrei Bobrov
Andrei Bobrov 2016 年 9 月 18 日
function cl = fun_for_piero(ID)
[a,~,c] = unique(ID);
ii = reshape(c,size(ID));
k = 1;
i1 = 1;
cl{k} = [];
c = 1:numel(a);
while ~isempty(ii)
t = any(ismember(ii,i1),2);
if ~any(t)
k = k + 1;
cl{k} = [];
i1 = c(1);
else
p = unique(ii(t,:));
cl{k} = [cl{k};sort(a(p(:)))];
ii = ii(~t,:);
c = setdiff(c,p);
i1 = p(:);
end
end

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

カテゴリ

ヘルプ センター および File ExchangeCluster Analysis and Anomaly Detection についてさらに検索

質問済み:

2016 年 9 月 16 日

コメント済み:

2016 年 9 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by