Filter löschen
Filter löschen

How to generate the following Graph in MATLAB ?

2 Ansichten (letzte 30 Tage)
charu shree
charu shree am 21 Apr. 2023
Kommentiert: charu shree am 21 Apr. 2023
Hello all, I am trying to generate the following graph shown in image and compute the shortest distance between each nodes but not getting correctly. Specifically I am able to generate the graph with the code shown below but not able to compute shortest distance between each nodes.
sr = [1,2,2,2,3,3,3,4,5];
ta = [2,3,6,8,6,4,7,6,6];
G = graph(sr,ta);
plot(G)
Any help in this regard will be highly appreciated.

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 21 Apr. 2023
Use the function distances to find the shortest distance for all pairs of nodes
sr = [1,2,2,2,3,3,3,4,5];
ta = [2,3,6,8,6,4,7,6,6];
G = graph(sr,ta);
%The (i,j) elemenet is the shortest distance between node i and node j
d = distances(G)
d = 8×8
0 1 2 3 3 2 3 2 1 0 1 2 2 1 2 1 2 1 0 1 2 1 1 2 3 2 1 0 2 1 2 3 3 2 2 2 0 1 3 3 2 1 1 1 1 0 2 2 3 2 1 2 3 2 0 3 2 1 2 3 3 2 3 0
plot(G)
  2 Kommentare
charu shree
charu shree am 21 Apr. 2023
Bearbeitet: charu shree am 21 Apr. 2023
Thank you so much sir for your quick answer.
Could you please let me know what exactly matrix d is indicating i.e., I mean how to infer matrix d. And why its dimension is 8 by 8.
charu shree
charu shree am 21 Apr. 2023
Understood completely sir... Thanks a lot once again.....

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by