Calculate Hamming distance between two strings of binary digits in Matlab

I have two lines with the same length, containing 1 and 0. Each line has a length of 128 bits, and I want to calculate the Hamming distance between them. How can I do this?

eg. a = '1000001' and b = '1110001' → dist = Hamming (a, b);

+2
source share
2 answers

Use pdist with the hamming parameter.

+6
source
 dist = sum(a ~= b); 
+5
source

Source: https://habr.com/ru/post/1481171/


All Articles