Concatenation Error: Using num2bin did not produce expected results

조회 수: 2 (최근 30일)
VicPeters
VicPeters 2016년 5월 8일
댓글: VicPeters 2016년 5월 8일
Hi everyone, I need someone to help check my code. I use randi function to get two real numbers out from a matrix, and then concatenate the two real numbers after using num2bin to convert to binary. The output of the randi function gave different results each time as expected, but when I concatenate using horzcat the results over several iteration are just same instead of being different. I need help!
for d=1:(n-701)/100 % 5730 Iterations
checkin_pts1=data_tokyo(randi(n),[1 2]);
x1(d) = checkin_pts1(1,1);
y1(d) = checkin_pts1(1,2);
ch1= Initial_Pop(x1(d),y1(d));
end
for t=1:(n-701)/100 % 5730 Iterations
checkin_pts2=data_tokyo(randi(n),[1 2]);
x2(t) = checkin_pts2(1,1);
y2(t) = checkin_pts2(1,2);
ch2= Initial_Pop(x2(t),y2(t));
end
function single_chromo = Initial_Pop(val1,val2)
global chromo_length;global single_chromo;
global T;
%----------- Assign checkin values to known variable arrays ------------
% Convert checkin values to binary
%-------------------------------------------------------X
q=quantizer([8 3]);
bx = num2bin(q,val1);
%-------------------------------------------------------Y
q=quantizer([8 3]);
by = num2bin(q,val2);
chromo_length = horzcat(bx,by); % checkin_pts1, chekins_pts2
single_chromo = chromo_length %(rangeval,:) % Access individual xmosome
end
  댓글 수: 1
VicPeters
VicPeters 2016년 5월 8일
solved, the precision of the quantizer determines the depth of accurancy.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by