How to find separate graphs

2 visualizaciones (últimos 30 días)
NA
NA el 4 de En. de 2019
Comentada: NA el 5 de En. de 2019
I have this graph
Ro=[0 0 0 1 0 0;
0 0 1 0 1 0;
0 0 0 0 0 0;
0 0 0 0 0 0;
0 0 0 0 0 0]
[row,col]=find(Ro==1)
G = graph(row,col);
plot(G)
I want to write a code that gives me set of separate graph. result shoud be [1,4],[2,3,5]
  1 comentario
GT
GT el 4 de En. de 2019
Hi Naime,
There probably is an easier way to do this, however I am on R2018b, and on MAC and this is what I quickly came up with:
Ro=[0 0 0 1 0 0;
0 0 1 0 1 0;
0 0 0 0 0 0;
0 0 0 0 0 0;
0 0 0 0 0 0];
[row,col]=find(Ro==1);
G = graph(row,col);
plot(G)
%%% my simple answer
a = G.conncomp;
myN = 1:size(G.Nodes,1);
for i =1:size(unique(a),2)
myAns{i} = myN(a==i);
end
myAns{:}

Iniciar sesión para comentar.

Respuesta aceptada

GT
GT el 4 de En. de 2019
Ro=[0 0 0 1 0 0;
0 0 1 0 1 0;
0 0 0 0 0 0;
0 0 0 0 0 0;
0 0 0 0 0 0];
[row,col]=find(Ro==1);
G = graph(row,col);
plot(G)
%%% my simple answer
a = G.conncomp;
myN = 1:size(G.Nodes,1);
for i =1:size(unique(a),2)
myAns{i} = myN(a==i);
end
myAns{:}
  3 comentarios
GT
GT el 4 de En. de 2019
Nice:) I did not know it was possible:)
NA
NA el 5 de En. de 2019
Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by