array A =
2 3
2 5
4 8
5 6
7 8
I'd like to get the result as 'conidx = [2 3 5 6] and [4 7 8]'.
One of the values of [2 3] exists in the 2nd row,
One of the values of [2 5] exists in the 4th row,
so [2 3], [2 5] and [5 6] are connected,
finally I can get the connected indices as [2 3 5 6].
Otherwise, one of the values of [4 8] exists in the 5th row,
so [4 8] and [7 8] are connected, finally I can get the connected indices as [4 7 8].
[3]<-->[2]<-->[5]<-->[6] and [4]<-->[8]<-->[7]
For those of you who don't have
graphconncomp
and don't want to compile Shai's mex function. I've posted a pure-matlab replacement forgraphconncomp
as part of gptoolboxIt's also ~10x faster than
graphconncomp
for large, sparse input.build a graph and use
graphconncomp
For those of you who do not have bioinformatics toolbox
My implementation of
graphconncomp
in mex:code of
graph_conn_comp.m
code for
graph_conn_comp_mex.cpp
to be compiled in matlab using