MATLAB: How to detect if any numbers in an array are equal

arrayMATLAB

I have an array of numbers, for example a = [1 2 2 5 5 7 7] I want to detect when number are repeating (for example 2, 5, and 7) and then add .001 to the second number that was repeated to get a result of [1 2 2.001 5 5.001 7 7.001]

Best Answer

A=[1 2 2 5 5 7 7];
[UniA,IA]=unique(A);
index=setdiff(1:numel(A),IA);
A(index)=A(index)+0.001