Sorting Equal Elements of Matrix into Groups in Cell Array

1 回表示 (過去 30 日間)
Chad
Chad 2020 年 6 月 10 日
コメント済み: Chad 2020 年 6 月 10 日
Lets say C is an nx2 matrix where n can range from 1 to 15. All elements of C can range from 1-6. I want to form groups in the form of a cell array of like pairs of numbers. C1 will be a cell array which describes the ways the numbers of C1 are connected. The easiest way to describe this is just by examples:
C = [1 2; 1 3; 2 3] then C1 = { [ 1 2 3] }
C = [3 4; 3 5; 3 6; 4 5; 4 6; 5 6] then C1 = { [ 3 4 5 6] }
C = [1 2; 1 6; 2 6; 3 4; 3 5; 4 5] then, C1 = { [1 2 6], [3 4 5] }.
C = [1 3; 1 4; 3 4; 5 6] then C1 = { [1 3 4], [5 6]}
C = [1 2; 3 6; 4 5] then C1 = { [1 2], [3 6], [4 5] }
Hopefully you can see the trend. Any help is appreciated.

採用された回答

Fabio Freschi
Fabio Freschi 2020 年 6 月 10 日
編集済み: Fabio Freschi 2020 年 6 月 10 日
I had the same problem to detect isolated nodes in a graph: conncomp is the matlab command that gets the job done:
% create the graph object
G = graph(C(:,1),C(:,2));
% get disconnected parts
bnd = conncomp(G,'OutputForm','cell');
  1 件のコメント
Chad
Chad 2020 年 6 月 10 日
Thank you, very easy and simple solution.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by