Home > custom > misc > euklid_W.m

euklid_W

PURPOSE ^

PURPOSE: create an euklidean distance spatial weight matrix

SYNOPSIS ^

function W = euklid_W(wsy,wsx,n)

DESCRIPTION ^

 PURPOSE: create an euklidean distance spatial weight matrix 
         (n x m 'moving-window' style matrix with distance to center cell
         weighted.)
 -------------------------------------------------------------------
 USAGE: W = euklid_W(wsy,wsx,n)
 where: [wsy] x [wsy] is the x and y size of the matrix (uneven!)
        and [n] specifies how to normalise the weight matrix. 
        Options for [n] are:
        1) 'norm' to create a normalised weight matrix (sum of all
        weights is 1 
        2) 'none' or NA for a non-normalised matrix (default)
 -------------------------------------------------------------------------
 OUTPUTS:
        [W] a matrix with weights for every cell except center.
 -------------------------------------------------------------------
 NOTES: Weights are the the euklidean distance to 
        the center cell. Center cell weight is zero.

 See also: euklid_invW

 Felix Hebeler, Geography Dept., University Zurich, March 2006.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function W = euklid_W(wsy,wsx,n)
0002 % PURPOSE: create an euklidean distance spatial weight matrix
0003 %         (n x m 'moving-window' style matrix with distance to center cell
0004 %         weighted.)
0005 % -------------------------------------------------------------------
0006 % USAGE: W = euklid_W(wsy,wsx,n)
0007 % where: [wsy] x [wsy] is the x and y size of the matrix (uneven!)
0008 %        and [n] specifies how to normalise the weight matrix.
0009 %        Options for [n] are:
0010 %        1) 'norm' to create a normalised weight matrix (sum of all
0011 %        weights is 1
0012 %        2) 'none' or NA for a non-normalised matrix (default)
0013 % -------------------------------------------------------------------------
0014 % OUTPUTS:
0015 %        [W] a matrix with weights for every cell except center.
0016 % -------------------------------------------------------------------
0017 % NOTES: Weights are the the euklidean distance to
0018 %        the center cell. Center cell weight is zero.
0019 %
0020 % See also: euklid_invW
0021 %
0022 % Felix Hebeler, Geography Dept., University Zurich, March 2006.
0023 if nargin < 2
0024     error('You need at least 2 input arguments for this function');
0025 end
0026 
0027 wsx=floor(wsx/2);
0028 wsy=floor(wsy/2);
0029 
0030 [X,Y] = meshgrid(-wsx:wsx,-wsy:wsy);
0031 W = sqrt(X.^2+Y.^2);
0032 
0033 if exist('n','var')
0034     if strcmp(n,'norm');
0035         W=W./sum(W(:));  %normalize W
0036     elseif strcmp(n,'none');
0037     else
0038         error('Specified option for n not available. Please specify either [norm] for normalized matrix or leave blank for inverse Euklidean weights.');     
0039     end
0040 end

Generated on Tue 24-Feb-2009 19:14:50 by m2html © 2003