필터 지우기
필터 지우기

HAMMING DISTANCE IN ONE ARRAY

조회 수: 1 (최근 30일)
Panayiotis Christodoulou
Panayiotis Christodoulou 2012년 5월 30일
Hello,
i have a 1000x19 double array.
The first column is the product id and from the second column until the 19 column there is only 1 and 0s.
Ex:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
15 1 0 0 0 1 0 1 1 1 0 0 0 1 1 0 0 0 1
27 1 0 0 0 1 0 1 1 0 0 0 0 0 1 0 0 1 0 0
I want to find the binary for a certain product id compare it with the rest binary sets and find the product that is closer to the first one.
Sorry about my english i hope i was clear :)
Thanks

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 5월 30일
eg:
data = [1:19;randi([15 27],6,1),randi([0 1],6,18)];
[n,m] = size(data);
num = data(2:end,2:end)*(2.^(m-2:-1:0)');
[ii,ii] = sort(abs(num - num(1)));
out = data(ii(2),:);
  댓글 수: 1
Panayiotis Christodoulou
Panayiotis Christodoulou 2012년 5월 30일
i try to test this answer but i get the following error:
Subscript indices must either be real positive integers or logicals.
1:19 starts from 1 ? i want it to start from 2 .
thanks

댓글을 달려면 로그인하십시오.

카테고리

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