Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentario
Pratik Anandpara
Pratik Anandpara el 10 de Mzo. de 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

Iniciar sesión para comentar.

Respuesta aceptada

KSSV
KSSV el 10 de Mzo. de 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 comentarios
Pratik Anandpara
Pratik Anandpara el 10 de Mzo. de 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 el 10 de Mzo. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by