MATLAB: Test different number(values or label) in matrix

matrix

hello, I want to detect different number in matrix?
for exmaple in a matrix:
0 0 0 0 0 0 0;
3 3 0 0 0 0 0;
3 3 3 0 0 0 0;
0 0 0 0 4 4 4;
0 0 5 5 0 0 0;
5 5 5 5 5 0 0;
How can I know the number of different values in this matrix, and index for any elements with same value?
Can I use function 'diff'?

Best Answer

number of different values, A is your matrix
numel(unique(A))
All code:
a=[0 0 0 0 0 0 0
3 3 0 0 0 0 0
3 3 3 0 0 0 0
0 0 0 0 4 4 4
0 0 5 5 0 0 0
5 5 5 5 5 0 0];
b=unique(a)
for i=2:numel(b)
c=find(a==b(i))';
fprintf('The value %d appears %d times, indices %s\n',b(i),numel(c),num2str(c))
end