Hi i want to know that how to plot a directed tree from a given 2d matrix. for example i have data in this from:
and i want to plot directed tree like this:
In which 2 4 5 6 are nodes (keeping 2 as root) and there will be an edge if value is other than zero. e.g. (2,4)=1
Thanks in advance

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 23 Mai 2017

1 Stimme

See graph() to construct a graph object, and then plot() the graph object to draw it.

3 Kommentare

lucksBi
lucksBi am 23 Mai 2017
thanks for your answer. I have tried that but it creates graph based on indexes like in my example nodes of graph are 1 2 3 4 not 2 4 5 6.
adj = [0 1 0 0;
0 0 0 1;
1 1 1 0;
0 0 1 1];
G = digraph(adj, {'2', '4', '5', '6'}, 'OmitSelfLoops');
plot(G)
lucksBi
lucksBi am 23 Mai 2017
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by