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

    %% Prepare Vectors for Exact Comparison
% Create a vector, |x|. Obtain a second vector, |y|, by transforming and
% untransforming |x|. This transformation introduces round-off differences
% to some elements in |y|.
x = (1:6)'*pi;
y = 10.^log10(x);

%%
% Combine |x| and |y| into a single vector, |A|. Use |uniquetol| to
% reconstruct |A|, treating the values that are within tolerance as equal.
A = [x;y]
[C,IA,IC] = uniquetol(A);
newA = C(IC)

%%
% You can use |newA| with |==| or functions that use exact equality like
% |isequal| or |unique| in subsequent code.
D1 = unique(A)
D2 = unique(newA)