How do you obtain the values for each of n-times simulation of a nested while loop?

1 次查看(过去 30 天)
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

采纳的回答

Shunichi Kusano
Shunichi Kusano 2019-2-7
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by