How to use splitapply/findgroups on clustered/non-sequential graphs

I implemented the splitapply function on a graph that has non-sequential clusters. The index numbers of the returned clusters were sequentially numbered but the graph vertices are not sequentially numbered. I want it to return the exact node indices from the original graph.
% The actual results: clusters: [1,2,3];[4,5,6]
% The expected results: clusters: [1,2,3];[6,8,9]
G = graph([1 1 2 6 6 8],[2 3 3 8 9 9]);
plot(G)
bins=conncomp(G);
clusters = splitapply(@(x) {x}, 1:numnodes(G), bins);
sample graph.png

Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Asked:

on 13 Feb 2019

Community Treasure Hunt

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

Start Hunting!