MATLAB: How to compare two matrix and then count each elements

MATLABmatrixmatrix array

The elements of A will be checked and compared with B, with each element count S will increase and with each absence count R will increase.
A=[3 5 7]
B=[1 3 4 5 7]

Best Answer

Some variety of these might do what you want (although those examples are not very enlightening)
>> S = nnz(ismember(A,B))
S = 3
>> R = nnz(ismember(B,A))
R = 3