How to determine number of edges ?
2 次查看(过去 30 天)
显示 更早的评论
Hi, below is the code for shortestpath:
%code
A = randi(1,8) ;
D = graph(A);
D.Edges.W3 = randi(13, numedges(D), 1);
D.Edges.Weight = D.Edges.W3;
p = plot(D,'o','EdgeLabel',D.Edges.Weight );
axis square;
grid on
path = shortestpath(D, 2, 5);
highlight(p,path,'NodeColor','g','EdgeColor','g')
end
The Result:
As the result shown that each of the point will generate 8 edges based on the "A = randi(1,8)" input. How can i determine the edges number manually?
Thanks.
6 个评论
Walter Roberson
2018-9-4
Yes, looks like the code I suggested in https://www.mathworks.com/matlabcentral/answers/416045-how-to-make-a-line-between-random-nodes-connection#answer_333928
But I am not certain what your question is? Are you trying to control the number of total edges that are created? Are you trying to control the minimum "degree" of each node? Are you trying to control the maximum degree? Are you trying to determine the degree of each node on the path between nodes 2 and 5 ?
采纳的回答
Image Analyst
2018-9-2
Since every node seems to go to every node (even including itself), wouldn't it just be simply N*N/2 = 8*8/2 = 32?
4 个评论
Walter Roberson
2018-9-4
The line I showed,
A = A - diag(diag(A));
prevents edges between a node and itself, provided that A is a square adjacency matrix.
更多回答(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!