%% Average Similar Values in Vector
% Create a vector of random numbers and determine the unique elements using a tolerance. Specify OutputAllIndices as true to return all of the indices for the elements that are within tolerance of the unique values.

A = rand(100,1);
[C,IA] = uniquetol(A,1e-2,'OutputAllIndices',true);

%
% Find the average value of the elements that are within tolerance of the value C(2).

C(2)
allA = A(IA{2})
aveA = mean(allA)

% Copyright 2015 The MathWorks, Inc.