|
Dear narrow!
> I have a matrix as below:
> a b c d e f g h i j
> 1 0 1 0 0 0 0 1 0 1
> 1 0 0 0 1 1 1 0 0 0
> 0 0 0 1 0 0 0 1 0 1
> 0 1 1 1 1 0 0 0 0 1
> 0 1 1 0 1 0 0 1 1 0
> 0 1 0 1 0 1 1 0 1 0
> 1 0 0 0 0 1 1 0 1 0
>
> I know how to search the exact same vetor, but if I want to find out
> the vectors that have 2 elements the same, for example, b,c and e have
> the 2 elements are the same. f,g,and i have 2 elements are the same,
> i, b have 2 elements are the same. How can I make use of row index or
> column index to find out which vectors are having the same 2 elements.
Are 'a', 'b', ... part of the matrix?!
b, c, e have 4 common elements, not 2. Or are the zeros no "elements". Please define the problem more precisely.
If you search ones at the same positions in 2 vectors, use AND:
b = [0,0,0,1,1,1,0]
c = [1,0,0,1,1,0,0]
and(b,c)
==> [0,0,0,1,1,0,0]
And to get the number of ones in the answer, just use SUM.
Good luck, Jan
|