I want to update my 'for loop'
6 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Rohit Pappu
on 28 Oct 2020
Edited: Rohit Pappu
on 28 Oct 2020
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
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!