From: "Ulrik Nash" <>
Newsgroups: comp.soft-sys.matlab
Subject: Identifying and counting common elements.
Date: Sat, 2 Nov 2013 18:58:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 9
Message-ID: <l53i00$s98$>
Reply-To: "Ulrik Nash" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1383418688 28968 (2 Nov 2013 18:58:08 GMT)
NNTP-Posting-Date: Sat, 2 Nov 2013 18:58:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2106050
Xref: comp.soft-sys.matlab:804697

Hi Group,

I have two matrices (A and B) each containing 0's and 1's. All I need is to count the number of places where 1's exist in the same position in the two matrices., but besides looping through, I can't seem to find the solution. I have tried ismember and intersection, but the result was not correct.

For example, in the following
A = [1 0;0 0]
B = [1 1;1 0]

The answer needed is 1.