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.
댓글 수: 0
채택된 답변
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.
댓글 수: 0
추가 답변 (1개)
Abdolkarim Mohammadi
2020년 8월 14일
편집: 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]);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!