Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of sledges2adjmat
Home > sltoolbox > graph > sledges2adjmat.m

sledges2adjmat

PURPOSE ^

SLEDGES2ADJMAT Creates an adjacency matrix from edge set

SYNOPSIS ^

function A = sledges2adjmat(n, nt, edges, varargin)

DESCRIPTION ^

SLEDGES2ADJMAT Creates an adjacency matrix from edge set

 $ Syntax $
   - A = sledges2adjmat(n, nt, edges, ...)

 $ Arguments $
   - n:            The number of (source) nodes
   - nt:           The number of (target) nodes
   - edges:        The matrix of edge set
   
 $ Description $
   - A = sledges2adjmat(n, nt, edges) creates an adjacency matrix 
     from the edge set. You can specify the following properties:
       - 'valtype':        the value type of the target matrix
                           - 'auto': if has value, make numeric matrix
                                     if no value, make logical matrix
                           - 'logical': make logical matrix always
                           - 'numeric': make numeric matrix always
                           (default = 'auto')
       - 'sparse':         whether to create a sparse matrix 
                           (default = true)
       - 'preprune':       whether to prune the edges first 
                           (default = false)
       - 'prunemethod':    the method used to prune the edge set
                           (default = [], means using default method)
                           refer to slpruneedgeset for the specification 
                           of the prune methods.
       - 'sym':            whether to create symmetric graph
       - 'symmethod':      the method to symmetrize the graph
                           (default = [], means using default method)
                           refer to slsymedgeset for the specification.

 $ Remarks $
   - The property sym can only be true when n == nt.

   - It is an integrated wrapper for slmakeadjmat, slsymgraph and
     slpruneedgeset.

 $ History $
   - Created by Dahua Lin, on Sep 9, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slmakeadjmat SLMAKEADJMAT Makes an adjacency matrix using edges and corresponing values
  • slpruneedgeset SLPRUNEEDGESET Prunes the edge set
  • slsymgraph SLSYMGRAPH Forces symmetry of the adjacency matrix of a graph
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • slparseprops SLPARSEPROPS Parses input parameters
This function is called by:
  • sladjmat SLADJMAT Constructs the adjacency matrix representation of a graph

SOURCE CODE ^

0001 function A = sledges2adjmat(n, nt, edges, varargin)
0002 %SLEDGES2ADJMAT Creates an adjacency matrix from edge set
0003 %
0004 % $ Syntax $
0005 %   - A = sledges2adjmat(n, nt, edges, ...)
0006 %
0007 % $ Arguments $
0008 %   - n:            The number of (source) nodes
0009 %   - nt:           The number of (target) nodes
0010 %   - edges:        The matrix of edge set
0011 %
0012 % $ Description $
0013 %   - A = sledges2adjmat(n, nt, edges) creates an adjacency matrix
0014 %     from the edge set. You can specify the following properties:
0015 %       - 'valtype':        the value type of the target matrix
0016 %                           - 'auto': if has value, make numeric matrix
0017 %                                     if no value, make logical matrix
0018 %                           - 'logical': make logical matrix always
0019 %                           - 'numeric': make numeric matrix always
0020 %                           (default = 'auto')
0021 %       - 'sparse':         whether to create a sparse matrix
0022 %                           (default = true)
0023 %       - 'preprune':       whether to prune the edges first
0024 %                           (default = false)
0025 %       - 'prunemethod':    the method used to prune the edge set
0026 %                           (default = [], means using default method)
0027 %                           refer to slpruneedgeset for the specification
0028 %                           of the prune methods.
0029 %       - 'sym':            whether to create symmetric graph
0030 %       - 'symmethod':      the method to symmetrize the graph
0031 %                           (default = [], means using default method)
0032 %                           refer to slsymedgeset for the specification.
0033 %
0034 % $ Remarks $
0035 %   - The property sym can only be true when n == nt.
0036 %
0037 %   - It is an integrated wrapper for slmakeadjmat, slsymgraph and
0038 %     slpruneedgeset.
0039 %
0040 % $ History $
0041 %   - Created by Dahua Lin, on Sep 9, 2006
0042 %
0043 
0044 %% parse and verify input arguments
0045 
0046 if nargin < 3
0047     raise_lackinput('sledges2adjmat', 3);
0048 end
0049 
0050 if ~isempty(edges)
0051     ncols = size(edges, 2);
0052     if ndims(edges) ~= 2 || (ncols ~= 2 && ncols ~= 3)
0053         error('sltoolbox:invalidarg', ...
0054             'The edges should be a 2D matrix with two or three columns');
0055     end
0056 end
0057 
0058 opts.valtype = 'auto';
0059 opts.sparse = true;
0060 opts.preprune = false;
0061 opts.prunemethod = [];
0062 opts.sym = false;
0063 opts.symmethod = [];
0064 opts = slparseprops(opts, varargin{:});
0065 
0066 if opts.sym
0067     if n ~= nt
0068         error('sltoolbox:rterror', ...
0069             'The sym can only be true when n == nt');
0070     end
0071 end
0072 
0073 switch opts.valtype
0074     case 'auto'
0075         islogic = (ncols == 2);
0076     case 'numeric'
0077         islogic = false;
0078     case 'logical'
0079         islogic = true;
0080     otherwise
0081         error('sltoolbox:invalidarg', ...
0082         'Invalid value type of adjacency matrix: %s', opts.valtype);
0083 end
0084 
0085 
0086 %% main skeleton
0087 
0088 % prune
0089 if opts.preprune
0090     edges = slpruneedgeset(n, nt, edges, opts.prunemethod);
0091 end
0092 
0093 % make adjmat
0094 
0095 A = slmakeadjmat(n, nt, edges, [], islogic, opts.sparse);
0096 
0097 % symmetrize
0098 if opts.sym
0099     A = slsymgraph(A, opts.symmethod);
0100 end
0101

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com