How to measure the hamming distnace between the rows of a matrix?

8 次查看(过去 30 天)
hello,
how can I find the hamming distance among the rows of a matrix A without repeation. For example:
A=[ 0,1,1,1,0,1,0;
0,1,0,1,1,1,1;
1,1,0,1,0,0,0;
1,1,1,1,1,1,0;
1,0,0,0,1,1,0 ]
then, I want to get the hamming distance of rows (1,2), (1,3), (1,4), (1,5) , (2,3), (2,4), (2,5), (3,4), (3,5), and (4,5).
So, how we could do that?
Regards,

采纳的回答

Star Strider
Star Strider 2020-3-22
Use the pdist2 function, and specifically the Distance argument to specify 'hamming' as the metric.
Example —
A=[ 0,1,1,1,0,1,0;
0,1,0,1,1,1,1;
1,1,0,1,0,0,0;
1,1,1,1,1,1,0;
1,0,0,0,1,1,0 ];
for k1 = 1:size(A,1)-1
for k2 = k1+1:size(A,1)
D(k1,k2) = pdist2(A(k1,:),A(k2,:), 'hamming');
end
end

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by