how to generate chromosome?

5 次查看(过去 30 天)
Matlab Code for generating a random population of 40 chromosome having 20 genes each. Value of the genes are 0 and 1.

采纳的回答

Sara Boznik
Sara Boznik 2020-8-15
Is maybe this what are you looking for?
chromo=40;
gene=20;
for i=1:1:chromo
for j=1:1:gene
pop=randi([0,1]);
A(:,j)=[pop]
end
B(i,:)=A(:,j)
end
[m,n]=size(B) %just for test
B is matrix with m=40 and n=20, so you have 40 choromosomes with each having 20 genes.
Best of luck.

更多回答(1 个)

Abdolkarim Mohammadi
编辑:Abdolkarim Mohammadi 2020-8-15
Assuming you want search agents in the rows and design variables in the columns:
PopulationSize = 40;
nvars = 20;
Population = randi ([0,1], [PopulationSize,nvars]);

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by