I have matrix A
in Matlab of dimension hxk
and a matrix B
of dimension yxk
. I want to construct a vector C
of dimension yx1
listing in each row j
how many times B(j,:)
appears in A
.
A == B will return a matrix the same size as A (and B) telling you which elements of A are equal to the corresponding element of B. isequal(A, B) will return a single true/false telling you if all the elements of A are the same as the ones in B.
Two matrices are said to be identical if and only if they satisfy the following conditions: Both matrices have the same number of rows and columns. Both matrices have the same corresponding elements.
One of the ways to do this is to create a matrix C containing the maximum of A and B (element by element) and then checking if this new matrix is same as A or not.
M = mode( A ) returns the sample mode of A , which is the most frequently occurring value in A . When there are multiple values occurring equally frequently, mode returns the smallest of those values.
If you are looking for perfect matches, one solution with bsxfun
-
C = squeeze(sum(all(bsxfun(@eq,A,permute(B,[3 2 1])),2),1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With