フィルターのクリア

I want to update my 'for loop'

6 ビュー (過去 30 日間)
Hyerin Park
Hyerin Park 2020 年 9 月 28 日
編集済み: Rohit Pappu 2020 年 10 月 28 日
Dear community.
I want to update my 'for loop' to get a full valid response.
for example, I want to get 5 'Space response time' regardless of some Invalid response(that didn't push space key at response phase)
so i put 'Invalid' variable to update 'TrialN', but it didn't work.
Here is my sample code.
Thanks a lot in advance for any idea...
trialtest = 5;
invalid = 0;
trialN = trialtest + invalid
spaceTime = 1.5
spaceKey = KbName('space');
tflip = [];
for T = 1: trialN
Screen('DrawLine',w, 0, cx-10, cy, cx+10, cy, 3);
Screen('DrawLine',w, 0, cx, cy-10, cx, cy+10, 3);
Screen('Flip',w);
WaitSecs(1); %초 생각해봐야 함
Screen('FrameOval',w,0,[cx-40,cy-40,cx+40,cy+40],4);
fixOnset = Screen('Flip',w,tflip);
[space spaceRT] = KeyResponse(spaceTime,0,spaceKey); % wait key to continue
mspaceRT = spaceRT*1000;
if space ==1
Screen('DrawLine',w, 0, cx-10, cy, cx+10, cy, 3);
Screen('DrawLine',w, 0, cx, cy-10, cx, cy+10, 3);
Screen('Flip',w);
DrawTextUni(w,['GOOD'],'center',0,-rect(4)*.3);
elseif space == 999
Screen('DrawLine',w, 0, cx-10, cy, cx+10, cy, 3);
Screen('DrawLine',w, 0, cx, cy-10, cx, cy+10, 3);
Screen('Flip',w);
DrawTextUni(w,['BAD'],'center',0,-rect(4)*.3);
invalid = invalid +1
end
trialN = trialtest + invalid % I put this code for update, but it doesn't work T.T
end

回答 (1 件)

Rohit Pappu
Rohit Pappu 2020 年 10 月 28 日
編集済み: Rohit Pappu 2020 年 10 月 28 日
For loop does not support dynamic update of its conditions. A better alternative would be to use while loop instead
% Initialize t
t = 1;
while(t<=trialN)
% Block of code to be executed trialN times
t+=1; %Increment t
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by