Sorting Equal Elements of Matrix into Groups in Cell Array

4 visualizaciones (últimos 30 días)
Chad
Chad el 10 de Jun. de 2020
Comentada: Chad el 10 de Jun. de 2020
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.

Respuesta aceptada

Fabio Freschi
Fabio Freschi el 10 de Jun. de 2020
Editada: Fabio Freschi el 10 de Jun. de 2020
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');

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by