%% Unique Elements in Presence of Numerical Error
% Create a vector x. Obtain a second vector y by transforming and untransforming x. This transformation introduces round-off differences in y.

x = (1:6)'*pi;
y = 10.^log10(x);

%
% Verify that x and y are not identical by taking the difference.

x-y

%
% Use unique to find the unique elements in the concatenated vector [x;y]. The unique function performs exact comparisons and determines that some values in x are not exactly equal to values in y. These are the same elements that have a nonzero difference in x-y. Thus, c contains values that appear to be duplicates.

c = unique([x;y])

%
% Use uniquetol to perform the comparison using a small tolerance. uniquetol treats elements that are within tolerance as equal.

C = uniquetol([x;y])

% Copyright 2015 The MathWorks, Inc.