필터 지우기
필터 지우기

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