0001 function A = sledges2adjmat(n, nt, edges, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
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
0087
0088
0089 if opts.preprune
0090 edges = slpruneedgeset(n, nt, edges, opts.prunemethod);
0091 end
0092
0093
0094
0095 A = slmakeadjmat(n, nt, edges, [], islogic, opts.sparse);
0096
0097
0098 if opts.sym
0099 A = slsymgraph(A, opts.symmethod);
0100 end
0101