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

for loopMATLABwhile loop

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

Best Answer

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.