Effacer les filtres
Effacer les filtres

check answer in range otherwise do again process with random generated number check until all digit of loop in range

1 vue (au cours des 30 derniers jours)
for k1=1:10 %set population generation limit her
pop1h(k1)=randi([200 1150],1,1 ); %random genertor limit n*3 mean n-row and 3-three colum
end
pop=pop1h*2
if pop<500;
break
else
continue
end
  1 commentaire
Pratik Anandpara
Pratik Anandpara le 10 Mar 2017
pop1h generate 10 random number from 200 to 1150 now need to check this answer pop=pop1h*2 if this answer is<500 than not valid again new 10 digit generate and do same process untill condition satisfy

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 10 Mar 2017
for k1=1:100 %set population generation limit her
pop1h=randi([200 1150],1,1 ); %random genertor limit n*3 mean n-row and 3-three colum
pop=pop1h*2 ;
if pop<500;
disp('condition satisfied loop exited') ;
break
else
continue
end
end
  7 commentaires
Pratik Anandpara
Pratik Anandpara le 10 Mar 2017
i want final answer in 10 digit array after put value in equation POP=POP1H*2... and all 10 digit follow --pop>500 after got 10 digit in this range stop
KSSV
KSSV le 10 Mar 2017
count = 0 ;
N = 10 ;
iwant = zeros(N,1) ;
for k1=1:100 %set population generation limit her
pop1h=randi([200 1150],1,1 ); %random genertor limit n*3 mean n-row and 3-three colum
pop=pop1h*2 ;
if pop > 500;
count = count+1 ;
iwant(count) = pop ;
if count == N
break
end
else
continue
end
end
This can be achieved without loop also

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by