nonduplicate

Makes all values of input array distinct - used to get interp1 to work when x data has duplicates.
1K Downloads
Updated 21 Mar 2019

View License

% function xout = nonduplicate(xin)
%
% written so that interp1 doesn't return error:
% 'The values of X should be distinct.'
%
% does not sort data
% checks for duplicate values in xin
% returns xout where all values are distinct
%
% if duplicates found, separates values by small value (eps)
%
% input xin must be 1D
%
% useage:
% x = nonduplicate(x);
%
% yi = interp1(nonduplicate(x),y,xi)
%
% Example:
% interp1([1,1,2],[1,1,2],1.5)
% returns an error.
%
% interp1(nonduplicate([1,1,2]),[1,1,2],1.5)
% works just fine.
%
% written by Nathan Tomlin, nathan.a.tomlin@gmail.com
% v2: update 190321 after tip from Natalia Aziares Aguayo <n.aziares.a@gmail.com>
% same as listed here: https://stackoverflow.com/questions/13407030/desort-a-vector-undo-a-sorting
%
% should probably use consolidator instead

Cite As

Nathan Tomlin (2024). nonduplicate (https://www.mathworks.com/matlabcentral/fileexchange/26470-nonduplicate), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
2.0.0.0

Fixed problem so keeps correct order of input array.

1.0.0.0