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