MATLAB: How can i compare one vector with the other vector when all the stored in a matrix.

vector comparison

i have matrix B in which vectors are stored row wise i.e.
B= [ 12 34 56 78
34 76 98 21
98 76 56 34
12 34 56 78
12 34 56 78
34 76 98 21
22 43 66 90
89 65 45 10
22 43 66 90
22 43 66 90 ]
here i the above matrix B
first row corresponds to one vector i.e 12 34 56 78
second row corresponds to second vector i.e 98 76 56 34
and so on...
i want to compare all these vectors with each other in order to know which are the vectors that are same.....
i.e. 1st 4th and 5th row of the matrix are same 2nd and 6th row are same 7th 9th and 10th row are same and so on…
for ind = 1: number_Of_Rows
row1=ind;
vector1=B(ind,:);
row2=ind+1;
vector2=B(ind+1,:);
if(vector1==vector2)
fprintf('\n rows that are same are %d, %d\n',row1,row2);
end
end
the problem with the above code is that, suppose if row 1, 3 , 5, 6 are same then it returns as:
row 1,3 are same
row 3,5 are same
row 5,6 are same
what i want is to return the output as: row 1, 3 ,5 ,6 are same rather than row 1, 3 and row 3, 5 and row 5,6 are same
can u help me in doing so?

Best Answer

Hi.
B= [ 12 34 56 78
34 76 98 21
98 76 56 34
12 34 56 78
12 34 56 78
34 76 98 21
22 43 66 90
89 65 45 10
22 43 66 90
22 43 66 90 ];
[C, ia, ic] = unique(B,'rows');
fprintf('\n rows that are same are:\n\n');
for i=1:size(C,2)
idx=find(ic==i);
disp(idx')
end