Get node names after a graph condensation
显示 更早的评论
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 :

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 :

So I have 6 strongly connected components , but my problem is that I lost the node names , I want to get something like :

Is that any way to get the nodes names in the result of the condentation ?
Thanks.
采纳的回答
更多回答(1 个)
Walter Roberson
2017-12-4
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 个评论
Christine Tobler
2017-12-4
Very nice!
stam dadi
2017-12-4
Walter Roberson
2017-12-4
I wouldn't have known the calls to make without Christine's post.
stam dadi
2017-12-5
Steven Lord
2017-12-5
It shouldn't be a struct. In your original code it was the output of a call to condensation, which would return a digraph if called with a digraph. Walter and Christine's codes modified that digraph, specifically the names of the digraph's nodes.
Walter Roberson
2017-12-5
You would get a struct as an output if you had assigned the output
C = condensation(G);
to some other variable name than C
stam dadi
2017-12-5
Waseem AL Aqqad
2021-11-27
Wow! Thanks.
类别
在 帮助中心 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!