Plot directed graph from 2D matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
lucksBi
am 23 Mai 2017
Kommentiert: lucksBi
am 23 Mai 2017
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/164340/image.bmp)
and i want to plot directed tree like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/164342/image.bmp)
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
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 23 Mai 2017
See graph() to construct a graph object, and then plot() the graph object to draw it.
3 Kommentare
Walter Roberson
am 23 Mai 2017
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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!