MATLAB Answers

how to plot the directed graph using NxN matrix in matlab

2,205 ビュー (過去 30 日間)
Hi friends ,
I have a matrix with 30x30 , where the first row and first column representing the nodes just as shown below .
1- I want to plot a directed graph between the nodes using the edges values between the nodes
2- I want to to apply the threshould (thr = 0.2) to plot the the graphs using the edges above 0.2.
Note: the columns are the sources and the rows are the receivers.
Fp1 Fp2 F7 F3
Fp1 0.409 0.0146 0.009 0.0069
Fp2 0.55 0.512 0.005 0.0309
F7 0.035 0.001 0.705 0.0010
F3 0.025 0.061 0.44 0.534

  0 件のコメント

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

採用された回答

Hari Krishna Ravuri
Hari Krishna Ravuri 2020 年 3 月 23 日
編集済み: Hari Krishna Ravuri 2020 年 3 月 23 日
I understand that you want to plot a directed simple graph.
“I want to plot a directed graph between the nodes using the edges values between the nodes”
You can create a directed graph by passing the adjacency matrix to digraph function as shown below
G = digraph([1 1 2],[2 3 1])
You may now plot a directed graph by passing the directed graph to the plot function as shown below
plot(G)
“I want to apply the threshold (thr = 0.2) to plot the graphs using the edges above 0.2”
You may consider pre-processing the adjacency matrix before creating a directed graph using digraph. You may consider writing a small script using arrayfun for pre-processing. The syntax of arrayfunc is
B = arrayfun(func, A)
arrayfun(func, A) applies the function func to the elements of A, one element at a time.Here, func is a function handle and A is an array.
Hope this helps!

  1 件のコメント

Abdulhakim  Alezzi
Abdulhakim Alezzi 2020 年 3 月 23 日
Thank you very much Dear respected Hari Krishna Ravuri
Actually i have a matrix with x= 30x30 ,
However, with your help i just found how to do it .
It is as follow:
x(1:size(x,1)+1:end)=0; %clear diagonal
x(x<0.2)=0; %Dsired threshould
G = digraph(x);
plot (G);

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

その他の回答 (0 件)

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by