Clear Filters
Clear Filters

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

1 view (last 30 days)
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 Comment
Pratik Anandpara
Pratik Anandpara on 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

Sign in to comment.

Accepted Answer

KSSV
KSSV on 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 Comments
Pratik Anandpara
Pratik Anandpara on 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 on 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

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!