0001 function G = undirect(G) 0002 % UNDIRECT : Unweighted, undirected version of a graph. 0003 % 0004 % F = undirect(G) : G is a graph ("help formats" for details). 0005 % F is a 1-layer undirected equivalent of G, 0006 % with no self-loops. 0007 % 0008 % Pre-prototype version of 26 Aug 2005. JRG, SPR 0009 0010 % Strip the input down to a sparse adjacency matrix 0011 if isstruct(G) 0012 G = G.edgeWeights; 0013 end; 0014 if iscell(G) 0015 G = G{1}; 0016 end; 0017 % Make the diagonal zero unless it already is 0018 if any(diag(G)) 0019 G = G-diag(diag(G)); 0020 end; 0021 % Make it logical and symmetric unless it already is 0022 if ~islogical(G) || ~issym(G) 0023 G = G | G'; 0024 end;