문제

how can I calculate the hamming distance between two binary matrices?

for example:

A = [ 1 0 1; 1 1 1 ];
B = [ 1 0 0 ; 0 0 1 ];

Thanks so much!

도움이 되었습니까?

해결책

If by Hamming distance you mean an element-wise distance between two matrices you can simply use xor:

D = xor(A,B);

And the total distance over elements:

D_total = nnz(D);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top