annotate toolboxes/FullBNT-1.0.7/KPMtools/assignEdgeNums.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [edge_id, nedges] = assignEdgeNums(adj_mat)
wolffd@0 2 % give each edge a unique number
wolffd@0 3 % we number (i,j) for j>i first, in row, column order.
wolffd@0 4 % Then we number the reverse links
wolffd@0 5
wolffd@0 6 nnodes = length(adj_mat);
wolffd@0 7 edge_id = zeros(nnodes);
wolffd@0 8 e = 1;
wolffd@0 9 for i=1:nnodes
wolffd@0 10 for j=i+1:nnodes
wolffd@0 11 if adj_mat(i,j)
wolffd@0 12 edge_id(i,j) = e;
wolffd@0 13 e = e+1;
wolffd@0 14 end
wolffd@0 15 end
wolffd@0 16 end
wolffd@0 17
wolffd@0 18 nedges = e-1;
wolffd@0 19 tmp = edge_id;
wolffd@0 20 ndx = find(tmp);
wolffd@0 21 tmp(ndx) = tmp(ndx)+nedges;
wolffd@0 22 edge_id = edge_id + triu(tmp)';
wolffd@0 23
wolffd@0 24
wolffd@0 25 if 0
wolffd@0 26 ndx = find(adj_mat);
wolffd@0 27 nedges = length(ndx);
wolffd@0 28 nnodes = length(adj_mat);
wolffd@0 29 edge_id = zeros(1, nnodes*nnodes);
wolffd@0 30 edge_id(ndx) = 1:nedges;
wolffd@0 31 edge_id = reshape(edge_id, nnodes, nnodes);
wolffd@0 32 end