How do you obtain the values for each of n-times simulation of a nested while loop?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to iterate a 'while loop' 1000 times and get 1000 values of my i. But my code keeps giving me just one value. Please, what am I doing wrong?
evidInteg1(1)= 0.6
evidInteg2(1)= 0.6
reactionTime= zeros(1,1000)
i=1;
numSimulation= 1000
for trialNumber= 1:numSimulation
while evidInteg1< threshold & evidInteg2>0
noise1= sqrt(dTime)*randn;
noise2= sqrt(dTime)*randn;
evidInteg1(i+1)= evidInteg1(i)+ dTime*(neuronActivity1 -neuronActivity2)+ noise1-noise2;
evidInteg2(i+1)= evidInteg2(i)+ dTime*(neuronActivity2 -neuronActivity1)+ noise2-noise1;
i=i+1;
end
reactionTime(trialNumber)= i
end
0 commentaires
Réponse acceptée
Shunichi Kusano
le 7 Fév 2019
In your code, the resulted evidInteg1 and evidInteg2 remain in the next loop. Hence, once your condition (evidInteg1< threshold & evidInteg2>0) is satisfied, nothing happens after that trial, storing the i without change. Probably, you need to reset evidInteg1, evidInteg2, and i everytime you do a trial. Hence, the code after modification is:
reactionTime= zeros(1,1000)
numSimulation= 1000
for trialNumber= 1:numSimulation
evidInteg1(1)= 0.6
evidInteg2(1)= 0.6
i=1;
while evidInteg1(i) < threshold & evidInteg2(i) > 0
% yourcode
end
reactionTime(trialNumber)= i
clear evidInteg1 evidInteg2
end
hope this works.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!