- 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 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Amy Anderson
il 11 Mag 2020
Modificato: KALYAN ACHARJYA
il 11 Mag 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 Commenti
Risposta accettata
KALYAN ACHARJYA
il 11 Mag 2020
Modificato: KALYAN ACHARJYA
il 11 Mag 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!