1. Home
  2. NEIGHBOURS procedure

NEIGHBOURS procedure

Finds the neighbours of cells in a multi-dimensional array (R.W. Payne).

Options

DIAGONALS = string token Whether to include diagonal cells (include, exclude); default incl
NNEIGHBOURS = scalar Saves the number of neighbours that have been found

Parameters

DIMENSION = scalars Dimensions of the array
CELLS = variates Locations of the cells in each dimension
NEIGHBOURS = variates Locations of the neighbours in each dimension

Description

NEIGHBOURS finds the neighbours of a set of cells in a multi-dimensional array. TheDIMENSION parameter supplies a list of scalars defining the dimensions of the array (i.e. the number of cells in each direction). TheCELLS parameter supplies a list of variates giving the locations of the cells in each dimension. TheNEIGHBOURS parameter supplies a list of variates to save their locations of the neighbours.

The default is to include diagonal neighbours, but you can set option DIAGONALS=exclude to exclude them. The number of neighbours can be saved, in a scalar, by the NNEIGHBOURS option.

Options:DIAGONALS,NNEIGHBOURS.
Parameters:DIMENSION,CELLS,NEIGHBOURS.

See also

Procedure: ADJACENTCELLS.
Commands for: Spatial statistics.

Example

CAPTION    'NEIGHBOURS example'; STYLE=meta
VARIATE    [VALUES=2,3,3,4] x
&          [VALUES=2,3,4,5] y
NEIGHBOURS 6,7; CELLS=x,y; NEIGHBOURS=xn,yn
XAXIS      1; LOWER=0; UPPER=6
YAXIS      1; LOWER=0; UPPER=7
PEN        1,2; SYMBOL='circle'; SIZE=2; CSYMBOL='black','red'; CFILL='match'
DGRAPH     [TITLE='Including diagonal neighbours'] Y=y,yn; X=x,xn
NEIGHBOURS [DIAGONALS=exclude] 6,7; CELLS=x,y; NEIGHBOURS=xn,yn
DGRAPH     [TITLE='Excluding diagonal neighbours'] Y=y,yn; X=x,xn
Updated on February 6, 2023

Was this article helpful?