how would i change an undirected network into a directed network on matlab?

2 ビュー (過去 30 日間)
mariam shakoor
mariam shakoor 2021 年 4 月 6 日
回答済み: Christine Tobler 2021 年 4 月 6 日
hi, how would i change an undirected network into a directed network on matlab? what commannds could I use?

回答 (2 件)

Stephan
Stephan 2021 年 4 月 6 日
here is a small example:
A = [0 0 1; 0 0 1; 1 1 0]
ug = graph(A)
B = zeros(size(A,1))
B = B + triu(A)
dg = digraph(B)
subplot(2,1,1)
plot(ug)
subplot(2,1,2)
plot(dg)
read more here:
and at the linked pages at the bottom of the provided link.

Christine Tobler
Christine Tobler 2021 年 4 月 6 日
It depends on what you want to the directed graph to look like. To replace every undirected edge with two directed edges going in both directions, use
directedG = digraph(adjacency(undirectedG);
Note this will not copy over any node or edge properties of the original graph (for example node names). It also won't work if you have a multigraph (more than one edge connecting the same pair of nodes). There are other commands that will work for those cases.

カテゴリ

Help Center および File ExchangeUndirected Graphs についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by