cns_findnearest

Finds a range of indices of other cells that are the n nearest neighbors of a given cell in common coordinate space along a particular dimension.

Syntax

[v1 v2]          = cns_findnearest(m, z, dim, c, pz, n)
[v1 v2 ok]       = cns_findnearest(m, z, dim, c, pz, n)
[v1 v2 c1 c2]    = cns_findnearest(m, z, dim, c, pz, n)
[v1 v2 c1 c2 ok] = cns_findnearest(m, z, dim, c, pz, n)
m
A model structure.

z
The layer number of the given cell.

dim
The dimension name, or its number in layer z.

c
Index (along this dimension) of the given cell in layer z.

pz
Layer number in which we are searching for cells.

n
The number of nearby cells we want to find.

v1, v2
Range of indices of the found cells along this dimension in layer pz. These are guaranteed to be valid indices, i.e., between 1 and the dimension size. The range may be empty.

c1, c2
These are the same as v1 and v2 except they are not guaranteed to be valid -- they can be less than 1 or greater than the dimension size. (This usually happens close to an edge.) Essentially, these are the indices that correspond to the search we performed, but they are not necessarily the indices of actual cells.

ok
When only v1 and v2 are returned, ok is true iff (v1 == c1) and (v2 == c2). When both ranges are returned, ok is true iff the range (v1 - v2) is not empty.

Notes

The equivalent kernel macro is FIND_type_dim_NEAREST.