Code covered by the BSD License  

Highlights from
Matgraph

from Matgraph by Ed Scheinerman
Toolbox for working with simple, undirected graphs

Description of component
Home > matgraph > @graph > component.m

component

PURPOSE ^

component(g,v) -- find vertices in v's component of g

SYNOPSIS ^

function vtcs = component(g,v)

DESCRIPTION ^

 component(g,v) -- find vertices in v's component of g

CROSS-REFERENCE INFORMATION ^

This function calls:
  • matrix matrix(g) --- return (a copy of) the adjacency matrix of g
  • nv nv(g) --- number of vertices in g
This function is called by:
  • components components(g) --- find the components of the graph g

SOURCE CODE ^

0001 function vtcs = component(g,v)
0002 % component(g,v) -- find vertices in v's component of g
0003 
0004 n = nv(g);
0005 if (v < 1) || (v>n)
0006     error('Vertex out of range')
0007 end
0008 
0009 vec = zeros(n,1);
0010 vec(v) = 1;
0011 A = matrix(g);
0012 while(true)
0013     w = double(A*vec +vec > 0);
0014     if nnz(w) == nnz(vec)
0015         break
0016     end
0017     vec = w;
0018 end
0019 vtcs = find(vec);

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003

Contact us at files@mathworks.com