Editing a graph.

1 vue (au cours des 30 derniers jours)
Lewis Waswa
Lewis Waswa le 7 Juil 2023
Modifié(e) : Aniketh le 8 Juil 2023
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.

Réponses (1)

Aniketh
Aniketh le 8 Juil 2023
Modifié(e) : Aniketh le 8 Juil 2023
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));

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by