필터 지우기
필터 지우기

Editing a graph.

조회 수: 3 (최근 30일)
Lewis Waswa
Lewis Waswa 2023년 7월 7일
편집: Aniketh 2023년 7월 8일
I have a graph with about 115 nodes, all differently interconnected.
I would like to do two things: Plot the directed graph illustrating the connection between the nodes. And to return the longest path on the graph.
B=A(1:115,:);
G = digraph(B(:,1),B(:,2));
%layout(G,"force")
plot(G, "NodeFontSize",8,"MarkerSize",6);
The code provides me with a directed graph but it is too sparse. How can I standardize the distance between nodes and make it more compact? and secondly, how can I calculate the longest path?
Kindly assist.

답변 (1개)

Aniketh
Aniketh 2023년 7월 8일
편집: Aniketh 2023년 7월 8일
Hi Lewis, MATLAB provides options to change the strucure through the layout function. You can check out this page for more details. You could try out 'force' or 'subspace' arguments, see what works best for your case.
In case this is still too sparse for the graph you are implementing one method I would suggest would be to manually normalize the values in the graph while plotting and unnormalize right after, should be an easy enough workaround for the illustration part.
For the second part,assuming you want the longest distance 'on' the graph(longest edge) and not the distance between any two nodes, because that could become a NP hard problem,
Here is how you could do that:
distances = distances(G);
longest_path_length = max(distances(:));
longest_path = shortestpath(G, 1, numel(G.Nodes));

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by