hamming distance in one matrix

11 visualizaciones (últimos 30 días)
sami
sami el 21 de Sept. de 2014
Editada: VELAMMAL SHIVSHANKAR el 4 de Mzo. de 2020
greetings every body i want to calculate the hamming distance between the elements of row of random binary matrix that i have produces with function dec2bin. matrix as : 10100100010001001 ; 01110010100110010; 10000100001000111; 11100011111000011; how to calculate the HD between these lines.

Respuesta aceptada

Roger Stafford
Roger Stafford el 21 de Sept. de 2014
Editada: Roger Stafford el 21 de Sept. de 2014
B = [10100100010001001;
01110010100110010;
10000100001000111;
11100011111000011];
D = pdist(B,'minkowski',1);
or
D = pdist(B);
  3 comentarios
Roger Stafford
Roger Stafford el 21 de Sept. de 2014
Based on your original statement I assumed that you have a single matrix - I called it B - with four rows, each of which is a string of 17 characters and each character being either '0' or '1', as produced by 'dec2bin'. For example, the first row would be produced by
B(1,:) = dec2bin(84105,17); % (equals '10100100010001001')
The 'pdist' code I gave you using this B should have produced the six-element row vector
D = [12,6,8,12,8,8]
For example, the Hamming distance between the strings in the first two rows,
'10100100010001001'
'01110010100110010'
is 12 since that is the number of positions in which the two strings differ, and that would be the same as the minkowski-1 or euclidean distance.
I do not understand your expressions for Hamming distance. I quote from the Wikipedia website, http://en.wikipedia.org/wiki/Hamming_distance: "In information theory, the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different."
If you have trouble with 'pdist', an equivalent matlab code is:
B = ['10100100010001001';
'01110010100110010';
'10000100001000111';
'11100011111000011'];
C = nchoosek(1:4,2);
D = sum(B(C(:,2),:)~=B(C(:,1),:),2)';
sami
sami el 22 de Sept. de 2014
dear Roger thanks very much.... it works fine ,, take care

Iniciar sesión para comentar.

Más respuestas (2)

sravankumar v
sravankumar v el 16 de Nov. de 2017
if A1 is a binary image and divided in to 16x16 blocks using for loops then in the loop i want to calculate the hamming weight of A1(r+u+1:r+u+N,c+v+1:c+v+N) where r=1:N,c=1:N,u=0:N,v=0:N.please answer me as soon as possible

VELAMMAL SHIVSHANKAR
VELAMMAL SHIVSHANKAR el 4 de Mzo. de 2020
Editada: VELAMMAL SHIVSHANKAR el 4 de Mzo. de 2020
I have two random matrices of size 1*100. How can I calculate Hamming distance ?!!
If I am using pdist or pdist2 command it gives value as 1.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by