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

1 次查看(过去 30 天)
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 个评论
Pratik Anandpara
Pratik Anandpara 2017-3-10
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

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2017-3-10
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 个评论
Pratik Anandpara
Pratik Anandpara 2017-3-10
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 2017-3-10
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by