필터 지우기
필터 지우기

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by