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