Cody

Problem 638. Uniform binary crossover

Given two binary vectors, return the two children by combining the genes of them using a binary crossover mask.

More information: Uniform crossover

  • Parents and mask are row vectors of the same size N;
  • Output is a 2 x N matrix containing both children;
  • The first child must have genes from the first parent at the positions where the mask is true, and genes from the second parent where the mask is false;
  • The second child must have genes from the first parent at the positions where the mask is false, and genes from the second parent where the mask is true;
  • The mask is also supplied.

Example:

mask    = [1 0 0 0 1 1 1 0 0];
parent1 = [0 0 0 1 1 1 0 0 0];
parent2 = [1 1 0 0 1 0 1 1 0];
children = [0 1 0 0 1 1 0 1 0;
            1 0 0 1 1 0 1 0 0];

Solution Stats

67.53% Correct | 32.47% Incorrect
Last solution submitted on Oct 31, 2016

Problem Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more