code for assign the weight in a graph

3 ビュー (過去 30 日間)
priyanka
priyanka 2014 年 7 月 29 日
回答済み: Vishnu 2023 年 7 月 12 日
Using adjacency matrix a graph is created, now i want to assign the weight on the edges of graph. Could anybody tell me the code to assign the weight in a graph.

回答 (1 件)

Vishnu
Vishnu 2023 年 7 月 12 日
Hello @priyanka,
The instructions provided to add weights to a graph in MATLAB documentation are as follows:-
A = [0 5 3 0;0 0 1 2; 0 0 0 11; 0 0 0 0];
G = graph(A,'lower');
G.Edges.Weight = [10 20 30 40 50]';
As you can see in this example we have created a graph using an asymmetric adjacency matrix. Using the graph object returned by graph() we can add weights to its edges. for further reading please visit:- Graph Documentation

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by