if i have tow matrix how to crossover of them ?

3 次查看(过去 30 天)
if i have this matrix
A = [ 1 0 1 1
1 1 0 1
0 1 0 1
1 1 1 0]
B = [ 0 1 1 0
0 0 1 1
1 1 0 1
1 1 0 0]
i want to make them like that
A' = [ 1 0 1 1 1 1 0 1 0 1 0 1 1 1 1 0 ]
B' = [ 0 1 1 0 0 0 1 1 1 1 0 1 1 1 0 0 ]
then i want to randomly crossover in which every 4 element like a group
C1 = [ 1 0 1 1 0 0 1 1 0 1 0 1 1 1 0 0 ]
C2 = [ 0 1 1 0 1 1 0 1 1 1 0 1 1 1 1 0 ]
THEN I WANT TO return C1 and C2 like this
C1 = [ 1 0 1 1
0 0 1 1
0 1 0 1
1 1 0 0 ]
C2 = [ 0 1 1 0
1 1 0 1
1 1 0 1
1 1 1 0 ]

采纳的回答

Roger Stafford
Roger Stafford 2016-4-25
R = repmat(randi([0,1],4,1),1,4);
C1 = A.*R+B.*(1-R);
C2 = A.*(1-R)+B.*R;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by