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

조회 수: 8 (최근 30일)
Sarah A
Sarah A 2020년 3월 22일
댓글: Star Strider 2020년 3월 22일
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개)

카테고리

Help CenterFile Exchange에서 Hamming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by