www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/AverageSimilarValuesInMatrixExample.m

    %% 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.

% Copyright 2015 The MathWorks, Inc.

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)