Provide MATLAB representation for the following two graphs u

Provide MATLAB representation for the following two graphs using adjacency matrices: Edges have uniform length 1. How to find in MATLAB a shortest path from Node 4 to Node 6 (in both graphs)?

Solution

For Graph 1

s = [1 1 1 2 5];
t = [2 4 7 5 6];
weights = [1 1 1 1 1];
G = graph(s,t,weights);
plot(G,\'EdgeLabel\',G.Edges.Weight)
[path,d] = shortestpath(G,4,6)
B = digraph(s,t)
A = adjacency(B)

For Graph 2

s = [1 1 1 2 2 2 3 4 5];
t = [2 5 7 3 4 6 5 7 6];
weights = [1 1 1 1 1 1 1 1 1];
G = graph(s,t,weights);
plot(G,\'EdgeLabel\',G.Edges.Weight)
[path,d] = shortestpath(G,4,6)
B = digraph(s,t)
A = adjacency(B)

 Provide MATLAB representation for the following two graphs using adjacency matrices: Edges have uniform length 1. How to find in MATLAB a shortest path from No

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site