- Please define the "Items_Left" before the for loop (may be original number of items, during start the execute), as it used in the for loop counter also.
- The Items_Left will be only updated (-1), when the if condition true, otherwise it will remain same.
Update a for loop issue.
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi! I'm trying to create a counter to run through a for loop but update the for loop. There is a 0.1 probability of selecting the correct colored straw in a pool of 1000 straws and i want to figure out how many are lost each time time the trial is run for a total of 25 trials. So i am storing the outcome of running through each trial for the number of straws left. Any help would be appreciated to help me pin point what im missing!
so far I have
Initial_Number_Straws=1000
Total_Trials=1:1:25
Straws_Lost_Each_Trial=zeros(1,25)
Probability_Correct_Color=0.1
Straws_Lost_Each_Trial(1)=1000
for j=2:25
for i=1:Items_Left
probability=rand
if probability<=Probability_Correct_Color
Items_Left=Items_Left-1
end
Straws_Lost_Each_Trial(j)=Items_Left
end
댓글 수: 0
채택된 답변
KALYAN ACHARJYA
2020년 5월 11일
편집: KALYAN ACHARJYA
2020년 5월 11일
Here are my submission:
It would be easy to answer, if you could ask the question with representative problem (Quite simpler to get it than as actual scenario)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!