MATLAB: How to sum and compare the similar elements of 3 rows???

arraymatrix arraymatrix manipulation

I have a 5 by 5 matrix,
A=[1 1 1 0 1;
1 0 0 0 1;
1 1 0 0 1;
1 1 0 0 0;
0 0 0 1 1]
I want to sum 3 row elements randomly and count only when all three row elements are same otherwise no,for example,
rows: {1,3,4}=2
{2,4,5}=1
{1,4,5}=0
the three rows can be any 3 out of 5, it wont be having all combinations of 3 rows.
please please help me…. and please can you explain me that how will i take 3 rows. if i will compare 4 row element then what will be the coding. please please help me.

Best Answer

A=[1 1 1 0 1;
1 0 0 0 1;
1 1 0 0 1;
1 1 0 0 0;
0 0 0 1 1];
I think I understand the rule. For the first case:
rowList = [1,3,4];
she wants to look at just rows 1,3, and 4:
A_sub = A(rowList,:)
then identify the columns where all the elements are equal:
This is the trickiest bit. First used bsxfun to see if each element is equal to its own first row. Then check to see if that is true for ALL elements in that column.
A_equal_col = all(bsxfun(@eq,A_sub,A_sub(1,:)));
Finally, count up how many columns obey the rule:
A_sum = sum(A_equal_col)