MATLAB: How to make MatLab tell me what is the same in an array

arrayequal rowsMATLAB

I got a 10×3 array with 1s and 0s placed randomly.
V = round(rand(10,3))
I one case I get
V =
0 0 0
0 1 1
1 1 1
0 1 1
0 0 0
1 0 1
0 0 0
0 1 1
0 0 0
0 0 1
I want to make MatLab tell me which row are identical. So in this case I want to find out that V(1,:), V(5,:) and V(9,:) are equal, and that V(2,:), V(4,:) and V(8,:) are equal etc., without have to look at the array myself.

Best Answer

Use the unique function:
V = [0 0 0
0 1 1
1 1 1
0 1 1
0 0 0
1 0 1
0 0 0
0 1 1
0 0 0
0 0 1];
[Vu, ia, ic] = unique(V, 'rows');
Here, ‘Vu’ are the unique rows, (here 5), and ‘ic’ are the row indices corresponding to the occurrences of each element of ‘Vu’, in order. Experiment with it to see how it works.