Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab how to bitwise-AND of a vector and a matrix?

I want to find out the index of the matrix column in which the vector appears. My idea is to do AND of the vector over matrix and only the column that is the same will be 1 in the new vecotr. But I don't know how to do this. Below is example:

H =
0   0   0   0   1   1   1   1   1   1   1   1   0   0   0
0   1   1   1   0   0   0   1   1   1   1   0   1   0   0
1   0   1   1   0   1   1   0   0   1   1   0   0   1   0
1   1   0   1   1   0   1   0   1   0   1   0   0   0   1

S =
0   1   0   1

From that I want to get 2 as second column or even better vector

0 1 0 0 0 0 ... 0 

Since there is error in second column.

How can I do this in Matlab or even better Octave?

like image 585
gorgi93 Avatar asked Nov 26 '25 16:11

gorgi93


1 Answers

Not really sure how you tried to approach the problem. But with repmat or bsxfun it is as simple as this:

all(bsxfun(@eq,H,S'))
like image 88
Dennis Jaheruddin Avatar answered Nov 28 '25 06:11

Dennis Jaheruddin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!