Connected components in a graph
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Asaf McRock
 el 14 de Dic. de 2020
  
    
    
    
    
    Comentada: Asaf McRock
 el 15 de Dic. de 2020
            M=[1 2;2 5;3 4;4 6;6 7;6 8;6 9;6 10];
G=graph(M(:,1),M(:,2))
[bins,binsizes]=conncomp(G);
When I use the built in function conncomp, MATLAB always assumes that first component of graph G is the one which node 1 belongs to. 
The output bins in the given example is:
bins=[1	1	2	2	1	2	2	2	2	2]  How can I make the first component of my graph is where node 6 (for example) belongs to?
Your help would be appreciated.
Thanks!
0 comentarios
Respuesta aceptada
  Matt J
      
      
 el 14 de Dic. de 2020
        
      Editada: Matt J
      
      
 el 14 de Dic. de 2020
  
      M=[1 2;2 5;3 4;4 6;6 7;6 8;6 9;6 10];
G=graph(M(:,1),M(:,2));
[bins,binsizes]=conncomp(G);
idx=[2,1];
binsizes=binsizes(idx);
bins=idx(bins)
3 comentarios
  Matt J
      
      
 el 15 de Dic. de 2020
				You would just need to change idx to an appropriate permutation of 1:N, e.g.,
idx=[3,1,2,4]
Más respuestas (0)
Ver también
Categorías
				Más información sobre Undirected Graphs 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!

