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 Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by