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 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 5 日
What is unweighted graph?
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 日

3 投票

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 件のコメント

Muhammad Usman Saleem
Muhammad Usman Saleem 2016 年 4 月 6 日
I think g.Edges.Weight is bolding Edges of g? @Mike Garrity
Walter Roberson
Walter Roberson 2016 年 4 月 6 日
I do not understand what you mean by "bolding" in that question?
Jack Ie
Jack Ie 2016 年 4 月 6 日
It works in R2015b. how to do this in R2014b?
Mike Garrity
Mike Garrity 2016 年 4 月 6 日
Sorry, graph was introduced in R2015b.
Steven Lord
Steven Lord 2016 年 4 月 6 日
To "bold" all the edges (which I interpreted as making those with higher weight appear wider/thicker) use the LineWidth property.
plot(g,'EdgeLabel',g.Edges.Weight, 'LineWidth', 5*g.Edges.Weight)
If you want to change only the width of certain edges, say those with the highest weights, look instead at highlight.
% Plot the graph and increase the size of the arrows
% This will let us see the arrows more easily after highlighting
h = plot(g,'EdgeLabel',g.Edges.Weight, 'ArrowSize', 15);
% Locate the indices of the edges with the highest weights
edgesHighestWeight = find(g.Edges.Weight == max(g.Edges.Weight));
% Convert those indices into source and target nodes
[S, T] = findedge(g, edgesHighestWeight);
% Highlight the edges (S, T) where S and T are vectors of node indices
highlight(h, S, T, 'LineWidth', 5);
For this example only the three edges (8, 11), (8, 9), and (8, 10) should be highlighted. They're the only ones with weight 0.9.
sibabalo noludwwe
sibabalo noludwwe 2019 年 8 月 22 日
if I want my graph to be weighted on the vertices instead of weighting the edges what do I do?
Steven Lord
Steven Lord 2019 年 8 月 22 日
Change the MarkerSize property of the object returned by plot, either in the call to plot itself (like LineWidth in the first line of code in my message from April 6th 2016) or afterwards (for this you can use highlight like I did in the last line of code in my message, but specifying MarkerSize instead of LineWidth.)
Luara Antunes
Luara Antunes 2022 年 5 月 2 日
How to plot a weighted graph when the vertex-weighted graph has weights on its vertices, but not in edge-weighted?
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 日

1 投票

3 件のコメント

Muhammad Usman Saleem
Muhammad Usman Saleem 2016 年 4 月 7 日
thanks for sharing!
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および 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