about single point crossover??

6 visualizaciones (últimos 30 días)
eman ahmed
eman ahmed el 20 de Nov. de 2016
Editada: eman ahmed el 20 de Nov. de 2016
i'm writing aprog, convert word to numbers then binary then want to make crossover with random chromosome,the problem face me when the word is 3 letters output 4..and when 2 letters return error..can anyone help me plz
%convert the word 'THIS' to numbers according to the alphabetic sequence
prompt = 'Enter your text: ';
text= input(prompt,'s');
alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
[~,pos] = ismember(text,alphabet)
%convert each letter of the word to binary value
step3=de2bi(pos,'left-msb')
n = size(step3, 1);
l = size(step3, 2);
%generate the default chromosome (second parent)
Step4= randi([0, 1], 1,l)
Step4=[Step4;Step4;Step4;Step4];
%Choose a crossover point
cp = randperm(l-1, 1)
for i=1:n
breeders = [step3(i,:);Step4];
b1(i,:) = [breeders(1, 1:cp), breeders(2, cp+1:end)];
b2(i,:) = [breeders(2, 1:cp), breeders(1, cp+1:end)];
i=i+1;
end
b1=b1
b2=b2

Respuestas (0)

Categorías

Más información sobre Encryption / Cryptography 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!

Translated by