Effacer les filtres
Effacer les filtres

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

8 vues (au cours des 30 derniers jours)
Sarah A
Sarah A le 22 Mar 2020
Commenté : Star Strider le 22 Mar 2020
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,

Réponse acceptée

Star Strider
Star Strider le 22 Mar 2020
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 commentaires
Sarah A
Sarah A le 22 Mar 2020
It works. Thank you :)
Star Strider
Star Strider le 22 Mar 2020
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by