MATLAB: How to delete an repeated values in matrix

mathematicsmatrixmatrix manipulation

I have matrix like this, so how to delete repeated values in this case?
[a b]=[197.9040 11.6502 41.6502 41.3856 41.3856 0 197.9040
12.2180 51.2008 61.2008 104.3122 104.3122 0 12.2180];

Best Answer

A = [197.9040, 11.6502, 41.6502, 41.3856, 41.3856, 0, 197.9040, 12.2180, 51.2008, 61.2008, 104.3122, 104.3122, 0, 12.2180];
>> A(sum(bsxfun(@(a,b)abs(a-b)<1e-6,A,A(:)))<2)
ans =
11.6502 41.6502 51.2008 61.2008
Because your values are floating point it is best to avoid using eq, unique and the like, which only work for exactly identical values . Instead I used a tolerance of 1e-6, and values closer than this tolerance are assumed to be the same. You can change the tolerance to suit your values.