0

I have two matrixes such as

A =

     0     1     1     0
     0     0     1     1
     1     1     1     1
     1     0     1     0
     0     0     0     0

And B is B =

     0     1     1     0
     1     1     1     1
    -1    -1    -1    -1
     1     0     1     0
     0     0     0     0 

My task is how to count the number of different row by row between A and B. For example, the values of second row A and second row B is different, then count increase 1. The values in third row A and third row B are different, then count values is 2 now. Hence, the total different values row by row between A and B is 2. How to implement it by matlab?

Update: Thank Nemesis for the first question. Now I have a other question with matrix A. I want implement the bitxor between rows of matrix A. For simplicity, I use the rem function with 2. The index of rows that xor together are store in index array. This is my code

index=[1 2 4] % row 1,2,4 will xor
output=rem(sum(A(index,:)),2);

The above code works with index size >1. When index size equals 1 that mean the output values is copied from the a row of A. For example, index=[1] then ouput=A(1)=0 1 1 0. My problem is that I cannot apply the above code when index size equals 1. What is happen? Could you edit for me?

John
  • 2,838
  • 7
  • 36
  • 65

1 Answers1

2

This basically almost the same question as here, but with a small extension. Summarized, you can use the answer from @Andrey

ix = sum(sum(abs(A-B),2)~=0)

ix =

     2

Regarding the update of your question. The issue is, that sum for a single row will use 2 as direction (instead of default 1 that is what you want), since size(...,1)==1. You can force the direction in the following way:

output=rem(sum(A(index,:),1),2)
Community
  • 1
  • 1
Nemesis
  • 2,324
  • 13
  • 23