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
0 件のコメント
採用された回答
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 Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!