フィルターのクリア

convert adjacency matrix to edge list

12 ビュー (過去 30 日間)
muhammad ismat
muhammad ismat 2017 年 2 月 16 日
回答済み: Ratha Pech 2017 年 3 月 19 日
if i have this code
function el=adj2edge(adj)
n=length(adj); % number of nodes
edges=find(adj>0); % indices of all edges
el=[];
for e=1:length(edges)
[i,j]=ind2sub([n,n],edges(e)); % node indices of edge e
el=[el; i j adj(i,j)];
end
to convert adjacency matrix to edgelist i.e if i input
0 1 1
1 0 0
1 0 0
the output is
2 1 1
3 1 1
1 2 1
1 3 1
but i want
1 2
1 3
only

回答 (2 件)

Walter Roberson
Walter Roberson 2017 年 2 月 16 日
Remove the third column. Sort along the second dimension. unique() by rows.

Ratha Pech
Ratha Pech 2017 年 3 月 19 日
Replace the line edges=find(adj>0); % indices of all edges with edges=find(triu(adj>0)); % indices of all edges

Community Treasure Hunt

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

Start Hunting!

Translated by