Hi! It is my understanding that you want to mutate the matrix in such a way that when the mutated matrix is divided (vertical division) into 2 equal halves, the first row of the first half and the first row of the second half should contain at least 2 ones.
We can initially do the mutation and then proceed to check if the mutated matrix adheres to the above criteria. If it does not meet the specified condition, we can take appropriate action by reversing some of the mutations until the condition is satisfied.
Refer to the following code for better understanding. This code can be modified for your requirements.
disp(A);
1 1 0 1 1 0 1 0
1 1 1 0 0 0 1 1
0 0 1 1 1 1 1 1
indexes = (rand((size(A))) < Pm);
mid = round(size(B,2)/2);
count_of_1 = nnz(B(1,1:mid));
if(A(1,i) == 1 && B(1,i) == 0)
reverse_mut = reverse_mut+1;
else if( count_of_1 == 1)
if(A(1,i) == 1 && B(1,i) == 0)
count_of_1 = nnz(B(1,mid+1:end));
if(A(1,i) == 1 && B(1,i) == 0)
reverse_mut = reverse_mut+1;
else if( count_of_1 == 1)
if(A(1,i) == 1 && B(1,i) == 0)
disp(B);
1 0 1 0 1 1 0 0
0 0 0 1 1 0 0 0
1 1 0 0 1 0 1 1
Refer to the following link for a mutation code for a genetic algorithm.
Hope this helps.