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
  2 件のコメント
Sarah A
Sarah A 2020 年 3 月 22 日
It works. Thank you :)
Star Strider
Star Strider 2020 年 3 月 22 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHamming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by