finding cycles in directed graph
9 次查看(过去 30 天)
显示 更早的评论
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
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
2021-3-9
Got it! I solved the problem by converting my adjacency matrix using the sparse function.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!