Home > custom > grid_stats > neighbourhood_statistics.m

neighbourhood_statistics

PURPOSE ^

PURPOSE: calculates statistics within a window of size [mwsize]

SYNOPSIS ^

function value = neighbourhood_statistics(mwsize, sx, sy, grid)

DESCRIPTION ^

 PURPOSE:  calculates statistics within a window of size [mwsize] 
           (square block) around cell at index [sx][sy] on [grid]. 
 Returns vector [value(mean,median,1stquartile,3rdquartile,max,min,stdv)]
 -------------------------------------------------------------------
 USAGE: value = neighbourhood_statistics(mwsize, sx, sy, grid);
 where: [mwsize] size of the window to calculate statistics for 
                 (in cells, uneven)
        [sx],[sy] is the x and y index of the center cell
        [grid] is the grid with the cells to be analysed
 -------------------------------------------------------------------------
 OUTPUTS:
        [value] is a vector holding the statistics in the form of
        [value(mean,median,1stquartile,3rdquartile,max,min,stdv)]
 -------------------------------------------------------------------
 NOTES: Equivalent to block_statistics but does not need coordinates or
        window size in map units.

 SEE ALSO: block_statistics

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function value = neighbourhood_statistics(mwsize, sx, sy, grid)
0002 % PURPOSE:  calculates statistics within a window of size [mwsize]
0003 %           (square block) around cell at index [sx][sy] on [grid].
0004 % Returns vector [value(mean,median,1stquartile,3rdquartile,max,min,stdv)]
0005 % -------------------------------------------------------------------
0006 % USAGE: value = neighbourhood_statistics(mwsize, sx, sy, grid);
0007 % where: [mwsize] size of the window to calculate statistics for
0008 %                 (in cells, uneven)
0009 %        [sx],[sy] is the x and y index of the center cell
0010 %        [grid] is the grid with the cells to be analysed
0011 % -------------------------------------------------------------------------
0012 % OUTPUTS:
0013 %        [value] is a vector holding the statistics in the form of
0014 %        [value(mean,median,1stquartile,3rdquartile,max,min,stdv)]
0015 % -------------------------------------------------------------------
0016 % NOTES: Equivalent to block_statistics but does not need coordinates or
0017 %        window size in map units.
0018 %
0019 % SEE ALSO: block_statistics
0020 %
0021 % Felix Hebeler, Geography Dept., University Zurich, March 2006.
0022    m=floor(mwsize/2);
0023    block = reshape(grid(sy-m:sy+m,sx-m:sx+m),1,mwsize*mwsize);
0024 
0025    value=[mean(block),median(block),quantile(block,0.25),quantile(block,0.75),max(block),min(block),std(block)];
0026

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