How to mutate '0' to '1' and '1' to '0' in GA code Using MATLAB?

1 view (last 30 days)
Dear Sir/Madam,
Using matlab a got a population ( 16*30)
in between that population randomly, i want to change 64 values '0' to '1' and '1' to '0' randomly.
initial population created. It was shown in below.
010101010011000011011101100111 010110010011000011011101100110 010101010110000011011101100110 011111010011000011011101100101 011100010101000100011000100101 010110011000000011011010100101 011011010110000100011101100111 011110010101000100011110100101 011100010101000100011000100101 011111010011000011011101100101 010110010011000011011101100110 010101010011000011011101100111 010110010011000011011101100110 010110010011000011011101100110 011111010011000011011101100101 011011010110000100011101100111
If i am converting '0' to '1' and '1' to '0' randomly. It will give new population as shown below as a
010101010011000011011101100111 01101001100001111101100110 01110110000110111000110 011111100100010110110101 01110001010100000011000100101 010110110000000110010100101 0110110101100010111010011 0111100101100010011110100101 111000101100010000001010 01111101100011011101100101 010100100110000101111100110 010101001100011011101100111 0101010011000110111100110 0101100001000011111100110 11010011000 1011101100101 011110101000010001110111
in between population some gaps and square boxes shown ( it was missed ( copy & paste) here).
Kindly help me how to solve my problem.
Anticipating your favorable reply.
Thanks & Regards.

Answers (2)

Thorsten
Thorsten on 20 Feb 2013
Edited: Thorsten on 20 Feb 2013
R = rand(16, 30) > 0.5;
ind = ceil(numel(R)*rand(64,1));
R(ind) = R(ind) == 0;

Azzi Abdelmalek
Azzi Abdelmalek on 20 Feb 2013
A=['010101010011000011011101100111'
'010110010011000011011101100110'
'010101010110000011011101100110'
'011111010011000011011101100101'
'011100010101000100011000100101'
'010110011000000011011010100101'
'011011010110000100011101100111'
'011110010101000100011110100101'
'011100010101000100011000100101'
'011111010011000011011101100101'
'010110010011000011011101100110'
'010101010011000011011101100111'
'010110010011000011011101100110'
'010110010011000011011101100110'
'011111010011000011011101100101'
'011011010110000100011101100111']
idx0=find(A=='0')
idx1=find(A=='1')
idx=randperm(numel(idx0)),
ii0=idx(1:64)
idx=randperm(numel(idx1)),
ii1=idx(1:64)
A(idx0(ii0))='1';
A(idx1(ii1))='0';

Community Treasure Hunt

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

Start Hunting!