MATLAB: How to count the number of vector elements without repetition

countrepetition

Hi, I have a vector that contains repeated elements, How can I count the number of vector elements without repetition?
For example: a=[2 5 2 8 9 8 7 8 1]; I expect the result will be: count = 6

Best Answer

>> na=[2 5 2 8 9 8 7 8 1];
>> length(unique(na))
ans =
6
>>