How to plot a weighted graph?

조회 수: 85 (최근 30일)
Jack Ie
Jack Ie 2016년 4월 5일
댓글: Luara Antunes 2022년 5월 18일
for example: How to plot bellow graph?
G=[1 4 0.2
2 4 0.2
3 4 0.2
4 1 0.7
4 2 0.7
4 3 0.7
4 5 0.5
4 8 0.6
5 4 0.4
5 6 0.8
5 7 0.8
6 5 0.3
7 5 0.3
8 4 0.5
8 9 0.9
8 10 0.9
8 11 0.9
9 8 0.4
10 8 0.4
11 8 0.5
11 12 0.6
12 11 0.2];
and How to plot an unweighted graph?
  댓글 수: 3
Muhammad Usman Saleem
Muhammad Usman Saleem 2016년 4월 5일
also what is weighted graph? I know about weight mean not weighted graph
Walter Roberson
Walter Roberson 2016년 4월 6일
"A weight is a numerical value, assigned as a label to a vertex or edge of a graph. A weighted graph is a graph whose vertices or edges have been assigned weights; more specifically, a vertex-weighted graph has weights on its vertices and an edge-weighted graph has weights on its edges."
For example, if you were creating a pipeline network, then the weight might correspond to the carrying capacity of the pipe. If you were creating a road map, then the weight might correspond to the speed limit on the segment.

댓글을 달려면 로그인하십시오.

채택된 답변

Mike Garrity
Mike Garrity 2016년 4월 5일
Something like this?
G=[1 4 0.2; ...
2 4 0.2; ...
3 4 0.2; ...
4 1 0.7; ...
4 2 0.7; ...
4 3 0.7; ...
4 5 0.5; ...
4 8 0.6; ...
5 4 0.4; ...
5 6 0.8; ...
5 7 0.8; ...
6 5 0.3; ...
7 5 0.3; ...
8 4 0.5; ...
8 9 0.9; ...
8 10 0.9; ...
8 11 0.9; ...
9 8 0.4; ...
10 8 0.4; ...
11 8 0.5; ...
11 12 0.6; ...
12 11 0.2];
g = digraph(G(:,1),G(:,2),G(:,3));
plot(g,'EdgeLabel',g.Edges.Weight)
Requires R2015b. Do 'help digraph' to get more examples. You can do things like color the edges by the weights.
  댓글 수: 10
Steven Lord
Steven Lord 2022년 5월 2일
Add a property to the Nodes table as shown on this documentation page.
Luara Antunes
Luara Antunes 2022년 5월 18일
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 4월 6일
  댓글 수: 3
Joel Sande
Joel Sande 2016년 4월 11일
Hi, How to include digraph folder in Matlab 2014a ? thanks
Joel Sande
Joel Sande 2016년 4월 11일
편집: Joel Sande 2016년 4월 11일
I downloaded the folder digraph. I don t know how to use it in my code. I have the 2014a version.

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by