MATLAB Answers

Overlap of 2 logicals

8 views (last 30 days)
Charms
Charms on 24 Feb 2020
Commented: Star Strider on 24 Feb 2020
I have 2 logicals, B and B2 of the same size (120x9), and would like to find the number of overlaps of 1s(true) in B and B2 of the same row and column. Was wondering if there is any function to code for this. I have attached B and B2 for easy access.
Thank you :)

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 24 Feb 2020
Since ‘B’ and ‘B2’ have not yeat appeared, try this with synthetic versions of them:
B = randi([0 1], 5, 6) > 0
B2 = randi([0 1], 5, 6) > 0
C = B & B2
NumberOfOverlaps = nnz(C)
You can shorten the code to:
NumberOfOverlaps = nnz(B & B2)
I kept them separate to demonstrate how the code works.

  2 Comments

Charms
Charms on 24 Feb 2020
thank you star strider, totally overlooked & :)
Star Strider
Star Strider on 24 Feb 2020
As always, my pleasure!

Sign in to comment.

More Answers (0)