Function File: [x_new y_new w_new] = dedup(x, y, w, tol, nan_remove=true)

De-duplication and sorting to facilitate spline smoothing
Points are sorted in ascending order of x, with each set of duplicates (values with the same x, within tol) replaced by a weighted average. Any NaN values are removed (if the flag nan_remove is set).

Useful, for example, as a preprocessor to spline smoothing

Inputs:
x: n*1 real array
y: n*m array of values at the coordinates x
w: n*1 array of positive weights (inverse error variances); ones(size(x)) by default
tol: if the difference between two x values is no more than this scalar, merge them; 0 by default

Outputs: De-duplicated and sorted x, y, w

See also: csaps, bin_values.

Package: splines