calculating hamming distance and total hamming distance
25 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hi How can I calculate hamming distance and total hamming distance for binary matrices with different rows, as a= [0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 1 0 0; 0 1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 0; 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1; 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 1 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1];
Thank you in advance.
0 comentarios
Respuestas (1)
Sufiyan
el 8 de Abr. de 2023
Hi,
You can refer to the code below to calculate hamming distance and total hamming distance for binary matrices.
% input matrix a
a = [0 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 1 0 0;
0 1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 0;
0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1;
0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 1 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1];
d = pdist(a, 'hamming');
% Display the Hamming distances between rows as a square matrix
n = size(a, 1);
D = squareform(d);
D(logical(eye(n))) = NaN; % Set diagonal to NaN
disp('Hamming distances:')
disp(D)
% Calculate the total Hamming distance as the sum of all pairwise distances
total_d = sum(d);
disp(['Total Hamming distance: ' num2str(total_d)])
0 comentarios
Ver también
Categorías
Más información sobre Hamming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!