matthiasm@8: function [edge_id, nedges] = assignEdgeNums(adj_mat) matthiasm@8: % give each edge a unique number matthiasm@8: % we number (i,j) for j>i first, in row, column order. matthiasm@8: % Then we number the reverse links matthiasm@8: matthiasm@8: nnodes = length(adj_mat); matthiasm@8: edge_id = zeros(nnodes); matthiasm@8: e = 1; matthiasm@8: for i=1:nnodes matthiasm@8: for j=i+1:nnodes matthiasm@8: if adj_mat(i,j) matthiasm@8: edge_id(i,j) = e; matthiasm@8: e = e+1; matthiasm@8: end matthiasm@8: end matthiasm@8: end matthiasm@8: matthiasm@8: nedges = e-1; matthiasm@8: tmp = edge_id; matthiasm@8: ndx = find(tmp); matthiasm@8: tmp(ndx) = tmp(ndx)+nedges; matthiasm@8: edge_id = edge_id + triu(tmp)'; matthiasm@8: matthiasm@8: matthiasm@8: if 0 matthiasm@8: ndx = find(adj_mat); matthiasm@8: nedges = length(ndx); matthiasm@8: nnodes = length(adj_mat); matthiasm@8: edge_id = zeros(1, nnodes*nnodes); matthiasm@8: edge_id(ndx) = 1:nedges; matthiasm@8: edge_id = reshape(edge_id, nnodes, nnodes); matthiasm@8: end