Home > sgwt_toolbox > sgwt_meshmat.m

sgwt_meshmat

PURPOSE ^

sgwt_meshmat : Adjacency matrix for regular 2d mesh

SYNOPSIS ^

function A=sgwt_meshmat(dim,varargin)

DESCRIPTION ^

 sgwt_meshmat : Adjacency matrix for regular 2d mesh 

 function A=meshmat_p(dim,varargin)

 Inputs:
 dim - size of 2d mesh 
 Selectable control parameters:
 boundary - 'rectangle' or 'torus'

 Outputs:
 A - adjacency matrix

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % sgwt_meshmat : Adjacency matrix for regular 2d mesh
0002 %
0003 % function A=meshmat_p(dim,varargin)
0004 %
0005 % Inputs:
0006 % dim - size of 2d mesh
0007 % Selectable control parameters:
0008 % boundary - 'rectangle' or 'torus'
0009 %
0010 % Outputs:
0011 % A - adjacency matrix
0012 
0013 % This file is part of the SGWT toolbox (Spectral Graph Wavelet Transform toolbox)
0014 % Copyright (C) 2010, David K. Hammond.
0015 %
0016 % The SGWT toolbox is free software: you can redistribute it and/or modify
0017 % it under the terms of the GNU General Public License as published by
0018 % the Free Software Foundation, either version 3 of the License, or
0019 % (at your option) any later version.
0020 %
0021 % The SGWT toolbox is distributed in the hope that it will be useful,
0022 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0023 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0024 % GNU General Public License for more details.
0025 %
0026 % You should have received a copy of the GNU General Public License
0027 % along with the SGWT toolbox.  If not, see <http://www.gnu.org/licenses/>.
0028 
0029 function A=sgwt_meshmat(dim,varargin)
0030   control_params={'boundary','rectangle'};
0031   argselectAssign(control_params);
0032   argselectCheck(control_params,varargin);
0033   argselectAssign(varargin);
0034   if (numel(dim)==1)
0035     dim=[1 1]*dim;
0036   end
0037   % build adjacency matrix : find i,j coordinates of center points
0038   % and right and bottom neighbors, then build connectivity matrix.
0039   % For each valid center,neighbor pair, will add A(center,neighbor)=1
0040   % and A(neighbor,center)=1, so A will be symmetric
0041   N=prod(dim);
0042   [alli,allj]=find(ones(dim));
0043   % (ci(k),cj(k)) has neighbor (ni(k),nj(k))
0044   ci=[alli;alli];
0045   cj=[allj;allj];
0046   ni=[alli  ; alli+1];
0047   nj=[allj+1; allj];
0048   switch boundary
0049    case 'rectangle' 
0050     % prune edges at boundary
0051     valid=(ni>=1 & ni<=dim(1) & nj>=1 & nj<=dim(2));
0052     ni=ni(valid);
0053     nj=nj(valid);
0054     ci=ci(valid);
0055     cj=cj(valid);
0056     cind=dim(1)*(cj-1)+ci;
0057     nind=dim(1)*(nj-1)+ni;
0058    case 'torus'
0059     % wrap indices to make torus
0060     ni=mod(ni,dim(1))+1;
0061     nj=mod(nj,dim(2))+1;    
0062     cind=dim(1)*(cj-1)+ci;
0063     nind=dim(1)*(nj-1)+ni;
0064    otherwise
0065     error('unknown boundary option');
0066   end
0067   % assemble connection matrix
0068   A=sparse([cind,nind],[nind,cind],ones(1,2*numel(ni)),N,N);
0069

Generated on Tue 04-May-2010 16:00:20 by m2html © 2003