Interpolation.Nearest Method
Performs nearest-neighbor interpolation at a single point.
Definition
Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.0.0
C#
The y-value of the nearest data point to x.
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.0.0
public static double Nearest(
double[] xValues,
double[] yValues,
double x,
OutOfRangeMode outOfRangeMode = OutOfRangeMode.Throw,
double fillValue = NaN
)Parameters
- xValues Double[]
- The x-coordinates of the data points. Must be strictly increasing.
- yValues Double[]
- The y-coordinates of the data points.
- x Double
- The x-coordinate at which to interpolate.
- outOfRangeMode OutOfRangeMode (Optional)
- Specifies how to handle x-values outside the interpolation range.
- fillValue Double (Optional)
- The value to return when outOfRangeMode is Fill and x is out of range.
Return Value
DoubleThe y-value of the nearest data point to x.
Remarks
This method returns the y-value of the data point whose x-coordinate is closest to x. In case of a tie, the point with the smaller index is selected.
This method performs no allocations and is suitable for single-point evaluation.
Exceptions
| Argument | xValues or yValues is null. |
| Dimension | The lengths of xValues and yValues do not match. |
| Argument | xValues does not have at least 1 element, or the values in xValues are not strictly increasing. |
| Argument | x is outside the interpolation range and outOfRangeMode is Throw. |