Sorting Equal Elements of Matrix into Groups in Cell Array

1 次查看(过去 30 天)
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');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by