Help with subtraction in a "while" loop
이전 댓글 표시
I am coding a section of a task using psychophysics toolbox in which I am trying to use two keys on a button box to increase or decrease a participant's mood rating and a third key to finalize an answer. I am running into a problem in which once a key is selected (say, the third key, which corresponds to resp = 3) the subtraction just continues until another key is selected. I want to code it such that the program waits for a key response, increases/decreases/or finalizes the rating ONCE and then waits for an additional key response. I'm not sure where my code is going wrong, keep in mind that I've very novice in this area!
while GetSecs - starttiming <= trialtime;
resp = 0;
[h,w,~] = size(IMAGE);
aspectRatio = w/h;
height = 800;
width = height .* aspectRatio;
imageRect = [0 0 width, height];
centRect = CenterRectOnPointd(imageRect,screenXpixels * 0.5, screenYpixels * 0.5);
Screen('DrawTexture', expWin, currIMAGEtxr,[], centRect); % draws self assessment manikan to screen at centRect location
Screen('FrameRect', expWin, 0, centRect, 5);
DrawFormattedText(expWin, sprintf('Use the green and blue keys to change your valence rating.\n\nPress yellow to enter your selection.\n\n'),'center',100);
DrawFormattedText(expWin, sprintf('Your rating is %d.\n\n',rating_val),'center',950);
Screen('Flip', expWin);
if ~isempty(inputaddress)
[resp,datum] = SAM_resp_final(tp.buttonpolltime{1},inputaddress,...
outputaddress,trialtime,flipinterval); %collect participant's response
WaitSecs(.002); %wait 2ms as flnkrresp script writes to the parallel port
end
outp(outputaddress,0); %reset byte
if resp == 3;
rating_val = rating_val + 1;
continue
elseif resp == 4;
rating_val = rating_val - 1;
continue
elseif resp == 2;
Screen('DrawTexture', expWin, currIMAGEtxr,[], centRect); % draws IAPS to screen at centRect location
Screen('FrameRect', expWin, 0, centRect, 5);
DrawFormattedText(expWin, sprintf('Press the yellow key to confirm\n\nPress green or blue to change.'),'center',100);
DrawFormattedText(expWin, sprintf('Your rating is %d.\n\n',rating_val),'center',950);
Screen('Flip', expWin);
if resp == 3;
rating_val = rating_val + 1;
continue
elseif resp == 4;
rating_val = rating_val - 1;
continue
elseif resp == 2;
Screen('Flip', expWin);
return
end
elseif resp == 1;
Screen('DrawTexture', expWin, currIMAGEtxr,[], centRect); % draws SAM to screen at centRect location
Screen('FrameRect', expWin, 0, centRect, 5);
DrawFormattedText(expWin, sprintf('Incorrect key press!\n\nPress the yellow key to confirm.\n\nPress green or blue to change.'),'center',100);
DrawFormattedText(expWin, sprintf('Your rating is %d.\n\n',rating_val),'center',950);
Screen('Flip', expWin);
continue
elseif resp == 0;
continue
end
end
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Just for fun에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!