MATLAB: How to plot a weighted graph

graph theoryplot

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?

Best Answer

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.