Unrecognized function or variable 'graphconncomp'.

The original code is this. I cannot find the addon containing the graphconncomp function. Error in moseg.MosegAlgAffBase/evalsplit2 (line 389) The line of code accessing it is:
% First find connected components
[S,C] = graphconncomp(Wceps);
There is a potential alternative using the GPToolBox . However when using this function I get a different error:
Incorrect number or types of inputs or outputs for function conncomp.
Error in moseg.MosegAlgAffBase/evalsplit2 (line 413)
[S,C] = conncomp(Wceps);
If there a distribuion of Matlab I should use, or a specific package? (I used AddOn package search also).

1 Comment

I finally converted the adjecency matrix to digraph and applied the newer conncomp function (ver > R2015) to the graph. The graphconncomp applies only to the adj. matrix and is available in the older version.
[s, t] = find(triu(Wceps));
G = digraph(s, t);
[S,C] = conncomp(G,'Type', 'strong');

Sign in to comment.

Answers (1)

5 Comments

I tried this as well. It did not work for me. After adding the bioinformatics toolbox, I had the same error.
The biograph object and its methods were removed from Bioinformatics Toolbox in release R2022b according to the Release Notes. Replace your usage of that object and those methods with uses of the graph and/or digraph objects and their methods.
Thank you, this is what I am trying to do, as listed in my first comment, but I have downstream issues with the code. Initially, the code was simple:
[S,C] = graphconncomp(Wceps);
fprintf('Cluster %d has %d connected componenets\n', clustnum, S);
ix2 = cell(S,1);
But now, after building the digraph, I have an error:
Error using cell
Size inputs must be scalar.
The current code is:
upper_triangular = triu(Wceps);
[s, t] = find(upper_triangular);
G = digraph(s, t);
[S,C] = conncomp(G,'Type', 'strong');
% Find the counts in each connected component
fprintf('Cluster %d has %d connected componenets\n', clustnum, S);
ix2 = cell(S,1);
for i=1:S
ix2{i} = clustix(C==i);
end
numccsplit = numccsplit + S;
ix = cell(2*S,1);
The fprintf, shows the connected components, so I assume this works. However the cell gives me the error here
ix2 = cell(S,1);
By the way S looks like:
...
Columns 3,151 through 3,157
3112 3118 3028 3080 3090 3092 3093
Columns 3,158 through 3,164
3094 3096 3098 3099 3113 3114 3119
I think the error basically is saying I cannot pass a vector in cell() but I need a scalar there. Maybe the size of S....? not sure
Looking at the documentation for graphconncomp, it states that the outputs are the number of components found and a vector indicating to which component each node belongs:
The number of components found is returned in S, and C is a vector indicating to which component each node belongs.
Looking at the conncomp documentation, the first output bins contains information about which component contains each node and the second is the sizes of the components. It doesn't directly return the number of connected components.
Therefore the first output of conncomp is (with the default value for the OutputForm name-value argument) is the equivalent of the second output of graphconncomp. The number of elements in the second output of conncomp or the maximum value in the first output are the equivalent of the first output of graphconncomp.
But if you're just looking for which nodes are part of which components, you don't need to manually generate that list. If you specify 'cell' as the OutputForm, the first output of conncomp changes. In that case "bins is a cell array, and bins{j} contains the node IDs for all nodes that belong to component j." I think that's exactly what you're creating as your ix2 variable.
rng default
randomDigraph = graph(rand(10) < 0.125, 'upper')
randomDigraph =
graph with properties: Edges: [7x1 table] Nodes: [10x0 table]
plot(randomDigraph)
[connectedComponentVector, sizesOfComponents] = conncomp(randomDigraph)
connectedComponentVector = 1x10
1 1 1 1 2 2 3 4 1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
sizesOfComponents = 1x4
6 2 1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
numberOfConnectedComponents1 = numel(sizesOfComponents) % or
numberOfConnectedComponents1 = 4
numberOfConnectedComponents2 = max(connectedComponentVector)
numberOfConnectedComponents2 = 4
connectedComponentCells = conncomp(randomDigraph, 'OutputForm', 'cell')
connectedComponentCells = 1x4 cell array
{[1 2 3 4 9 10]} {[5 6]} {[7]} {[8]}
For this new error I used:
size(S,2)
instead of S. It cleared the error.

Sign in to comment.

Categories

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

Products

Release

R2024a

Asked:

on 23 Jul 2024

Commented:

on 23 Jul 2024

Community Treasure Hunt

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

Start Hunting!