Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare in Matlab two matrices of different dimension and get the frequency of equal rows?

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.

like image 271
TEX Avatar asked Aug 06 '14 13:08

TEX


People also ask

How do you compare two matrices equal in Matlab?

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.

How do you compare two matrices to be the same?

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.

How do you compare elements in a matrix in Matlab?

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.

How do you find the most frequent value in an array in Matlab?

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.


1 Answers

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))
like image 149
Divakar Avatar answered Oct 11 '22 17:10

Divakar