- 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.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Amy Anderson
am 11 Mai 2020
Bearbeitet: KALYAN ACHARJYA
am 11 Mai 2020
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 Kommentare
Akzeptierte Antwort
KALYAN ACHARJYA
am 11 Mai 2020
Bearbeitet: KALYAN ACHARJYA
am 11 Mai 2020
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!