Calculate Hamming distance between two strings of binary digits in Matlab

最后都变了- 提交于 2019-12-10 22:54:43

问题


I have two equal length strings containing 1's and 0's. Each string is 128-bits long, and I want to calculate the Hamming distance between them. What's the best way I can go about doing this?

e.g. a='1000001' and b='1110001' --> dist=Hamming(a,b);


回答1:


Use pdist with the hamming parameter.




回答2:


dist = sum(a ~= b);


来源:https://stackoverflow.com/questions/4178469/calculate-hamming-distance-between-two-strings-of-binary-digits-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!