MATLAB: Unique values per row

MATLABunique

Hi all, I'm struggling to figure a simple method to determine the number of unique values per row in a matrix. For example in the matrix [1 2 3; 4 4 5; 6 6 6]
I would expect the result to be [3, 2, 1] I've tried using unique() and histc but neither are giving me the result I am looking for. Thanks!

Best Answer

>> A=[1 2 3; 4 4 5; 6 6 6]
A =
1 2 3
4 4 5
6 6 6
>> sum(diff(sort(A,2),1,2)~=0,2)+1
ans =
3
2
1