i want to make an array in choosing PP.
RS=1 28702 1 7 5 2 3 9 8 4 11 6 10 122 28764 9 2 7 6 3 1 4 5 12 10 11 83 36438 4 1 9 2 10 7 12 8 6 3 5 114 37192 12 7 10 8 1 9 4 6 5 11 3 25 41182 9 4 10 7 1 3 6 8 5 2 11 126 43442 4 10 2 3 1 5 6 12 9 8 11 77 48650 8 7 1 4 9 10 2 11 12 3 5 68 51154 12 2 8 1 3 5 7 4 11 9 6 109 51412 10 6 4 2 7 1 8 5 3 12 9 1110 52796 8 2 4 5 3 6 1 7 12 11 9 1011 54018 5 4 2 8 7 10 11 3 6 12 1 912 65420 6 7 2 8 3 4 12 1 11 9 10 5
cp=0.4; % Crossover Percentage
np=2*round(cp*r/2); % Number of Offsprings (Parents)
valp=np/2; v=valp;n1=length(RS(:,1));PP=RS([1:v,n1-v+1:end],3:end); % for cycle crossover used p1, p2,p3,p4 saja
p1 = PP(1,:); p2 = PP(2,:); p3 = PP(3,:); p4 = PP(4,:);
instead of doing it manually, p1, p2, p3 and p4.. i want it to be an array so that whevever u change the value i didnt have to write it manually
however i got an error "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side" when i do it like
for i=1:np p(i) = PP (i,:); end
below is the result of PP
PP =1. 12 3 9 11 6 10 4 7 5 1 8 22. 2 6 9 8 10 11 5 4 12 3 1 73. 10 4 2 12 3 8 9 5 1 6 11 74. 8 1 10 12 5 9 7 6 11 3 4 2
Best Answer