It depends how do you define "neighbourhood" in your WSN network. There are several ways to define neighbourhood relation, for example:
- Nodes within a certain search radius.
- Nodes that their beacon satisfies a certain SINR, when received at the cluster head.
- The closest (n) nodes to your cluster head.
- The nodes inside the Voronoi cell of the cluster head.
If you are working with clustering you most probably need the last type of neighbourhood. In this case, you can follow these steps to create your own function:
For every Node (expect cluster heads)
Obtain the distance vector to all cluster heads
Use the function [Distance,Index] = min(distance_Vector) to find the index and the distance to the nearest cluster head