Unrecognized function or variable 'graphconncomp'.

12 vues (au cours des 30 derniers jours)
Mihai Mehedint
Mihai Mehedint le 23 Juil 2024
Commenté : Mihai Mehedint le 23 Juil 2024
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 commentaire
Mihai Mehedint
Mihai Mehedint le 23 Juil 2024
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');

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 23 Juil 2024
  5 commentaires
Steven Lord
Steven Lord le 23 Juil 2024
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]}
Mihai Mehedint
Mihai Mehedint le 23 Juil 2024
For this new error I used:
size(S,2)
instead of S. It cleared the error.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by