Clear Filters
Clear Filters

Uniform crossover with boolean population

1 view (last 30 days)
I have this code in matlab to find 'uniform crossover' for the same vector W
W=[12,5,6,78,9,3];
%Parameters
N=2;
G=10;
Pop=round(rand([N,G]));
%%Uniform crossover
id=logical(round(rand(size(pop)))); %index of genome from W2
Pop2=Pop(W(1:2:end),:);%Set Pop2=Pop W1
P2A=Pop(W(2:2:end),:);%Assemble Pop2 W2
Pop2(id)=P2A(id);%combine W1 and W2
I got an error message at the last part of the code : Index Exceeds Matrix Dimensions. How can i solve the error?

Accepted Answer

Walter Roberson
Walter Roberson on 5 Nov 2018
Pop is a different variable than pop. id will be the same size as pop.
Pop2 and P2A are formed by taking 3 subset rows from Pop. You then try to index them at id which is the full size of pop. That will fail unless pop is 3 or fewer rows and has no more columns than Pop does.

More Answers (0)

Categories

Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!