Plot directed graph from 2D matrix

조회 수: 4 (최근 30일)
lucksBi
lucksBi 2017년 5월 23일
댓글: lucksBi 2017년 5월 23일
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

채택된 답변

Walter Roberson
Walter Roberson 2017년 5월 23일
See graph() to construct a graph object, and then plot() the graph object to draw it.
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 5월 23일
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 2017년 5월 23일
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by