Get node names after a graph condensation
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
stam dadi
el 4 de Dic. de 2017
Comentada: Waseem AL Aqqad
el 27 de Nov. de 2021
I have an adjacency matrix adj and a cellarray nodeManes that contains names that will be given to the graph G that will be constructed from adj
So I use
G = digraph(adj,nodeNames);
And I get the following graph :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170618/image.png)
Now , I want to find the strongly connected components in G and do a graph condensation so I use the following :
C = condensation(G);
p2 = plot(C);
So I get the following graph :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170619/image.png)
So I have 6 strongly connected components , but my problem is that I lost the node names , I want to get something like :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170620/image.png)
Is that any way to get the nodes names in the result of the condentation ?
Thanks.
0 comentarios
Respuesta aceptada
Christine Tobler
el 4 de Dic. de 2017
Here is some code that does this:
bins = conncomp(G);
compNames = cell(max(bins), 1);
for ii=1:length(bins)
if isempty(compNames{bins(ii)})
compNames{bins(ii)} = G.Nodes.Name{ii};
else
compNames{bins(ii)} = [compNames{bins(ii)} ', ' G.Nodes.Name{ii}];
end
end
C.Nodes.Name = compNames;
plot(C);
There's no one-line command to combine several node names based on the vector of bins used in condensation, so I wrote a for-loop to do this instead.
2 comentarios
Más respuestas (1)
Walter Roberson
el 4 de Dic. de 2017
Stealing basic technique from Christine, and reworking it without a loop:
bins = conncomp(G);
temp = accumarray(bins.', (1:length(bins)).', [], @(IDX) {G.Nodes.Name(IDX)});
C.Nodes.Name = cellfun(@(CS) strjoin(CS, ', '), temp, 'uniform', 0);
10 comentarios
Ver también
Categorías
Más información sobre Directed 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!