finding cycles in directed graph

조회 수: 4 (최근 30일)
Josué Ortega
Josué Ortega 2020년 4월 5일
댓글: Emanuele Giacomuzzo 2021년 3월 9일
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
Emanuele Giacomuzzo
Emanuele Giacomuzzo 2021년 3월 7일
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 2021년 3월 9일
Got it! I solved the problem by converting my adjacency matrix using the sparse function.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by