Effacer les filtres
Effacer les filtres

if i have tow matrix how to crossover of them ?

3 vues (au cours des 30 derniers jours)
Firas Al-Kharabsheh
Firas Al-Kharabsheh le 25 Avr 2016
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 ]

Réponse acceptée

Roger Stafford
Roger Stafford le 25 Avr 2016
R = repmat(randi([0,1],4,1),1,4);
C1 = A.*R+B.*(1-R);
C2 = A.*(1-R)+B.*R;
  1 commentaire
Firas Al-Kharabsheh
Firas Al-Kharabsheh le 25 Avr 2016
How can i do this many times and take the best value as a matrix ?

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by