finding cycles in directed graph

4 visualizaciones (últimos 30 días)
Josué Ortega
Josué Ortega el 5 de Abr. de 2020
Comentada: Emanuele Giacomuzzo el 9 de Mzo. de 2021
I am creating a random adjacency matrix for a directed graph and I want to find the cycles. I am using the findcycles function that I found online
I have the following code
rand('seed',1)
n=5;
A=zeros(5);
x=zeros(1,n);
for i=1:n
A(:,i)=randperm(n);
end
A
adj=zeros(n);
for i=1:n
adj(i,A(1,i))=1;
end
view(biograph(adj))
findcycles(adj)
But I get the following error, any ideas?
Warning: Self connecting nodes are not allowed, ignoring the diagonal of CM.
> In biograph (line 160)
In tops (line 13)
Error: File: findcycles.m Line: 5 Column: 10
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use
brackets instead of parentheses.
Error in tops (line 14)
findcycles(adj)
  7 comentarios
Emanuele Giacomuzzo
Emanuele Giacomuzzo el 7 de Mzo. de 2021
I'm trying to make this code work for myself, but I have problems in running the graphtraverse function. The graph I am working with is - according to MATLAB - a non-sparse one. So the function won't work on it. Is there any function like graphtraverse that works on non-sparse matrices?
The attached file is my non-sparse adjacency matrix.
Cheers!
Emanuele Giacomuzzo
Emanuele Giacomuzzo el 9 de Mzo. de 2021
Got it! I solved the problem by converting my adjacency matrix using the sparse function.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by