Clear Filters
Clear Filters

check all matrix element and if any element is out of range do again process

4 views (last 30 days)
in one for loop i do 10-11 process and get matrix if matrix element is not in range than do again same process ,in first step generate element randomly so if after 10-11 process matrix is not satisfy than again loop rotate
for k1=1:10 %set population generation limit her
pop2h(k1)=randi([1 69],1,1);
end
pop2=pop2h'; %second matrix for bus location
secondpop=pop2h' ;
binss1=secondpop';
Y =secondpop(:) ;
sss=fliplr(de2bi(secondpop,8)); %convert in binary form of 10 bus location
childs1 =sss;
swapoddeven = reshape([2:2:size(sss, 1);
1:2:size(sss, 1)], 1, []);
childs1(swapoddeven, swappedcolumns2) = childs1(1:size(sss, 1), swappedcolumns2);
pop11=bi2de(fliplr(childs1)) ; %convert binary to decimal of child crossover stored in pop11
X11= pop11(:,1) ; %x11 set as all entry of bus location
totalpopop=[secondpop pop11] ;
totalpopsbus=totalpopop(:) ;
%mutation process
mutating1=totalpopsbus(rninte(1));
mutating2=totalpopsbus(rninte(2));
mutationpro=[mutating1;mutating2]; %here is mutation row set here 1
bqs=fliplr(de2bi(mutationpro,8)) ;
bins11=mutationpro';
c21=fliplr(de2bi(bins11,8));
childs2 =c21;
swapoddeven = reshape([2:2:size(c21, 1)
1:2:size(c21, 1)], 1, []);
childs2(swapoddeven, swappedcolumns2) = childs2(1:size(c21, 1), swappedcolumns2);
mutcr1=bi2de(fliplr(childs2)) ; %mutation after crossover save here
busslocation=[totalpopsbus(:);mutcr1] ; %save all entry of bus location here
busslocation matrix element is not between 1-69 than again rotate loop...check single element of busslocation

Answers (1)

Walter Roberson
Walter Roberson on 23 Dec 2016
try_again = true;
while try_again
try_again = false;
generate matrix elements
if any(matrix_element(:) > 69)
try_again = true;
end
end

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!