0

我在 MATLAB 中使用 psychtoolbox,我想让参与者从 0-9 对一串图像的失真进行评分。我试过使用 GetChar,但是当我运行脚本时,它不会等待用户给出响应,而是移动到下一个屏幕。关于如何解决这个问题的任何建议?

%using a loop to show images
for k=1:290
texture1(k)=Screen('MakeTexture',w,images{k});    
end
for k=1:145
Screen('DrawTexture',w, texture1(k), [], leftposition);
Screen('DrawTexture',w, texture1(k+145), [], rightposition);
Screen('DrawLines', w, allCoords,...
lineWidthPix, black, [xCenter yCenter], 2);
Screen(w,'Flip');
pause(0.2);
end


%rating text
DrawFormattedText(w,'Rate distortion 0-9','center','center',[255 255  255]);
Screen(w,'Flip');
GetChar();


%press space to finish
DrawFormattedText(w,'press space to finish','center','center',[255 255 255]);
Screen(w,'Flip');


% Wait for a key press
KbStrokeWait;

% Clear the screen
sca;
4

1 回答 1

0

这里发生了一些事情:您只是在循环完成后寻找按键,而不是存储按键的结果。

GetChar也很混乱(您可能想调用FlushEvents以清除队列,或者您可能会遇到(来自help GetChar):

如果在调用 GetChar 之前键入了一个字符,则 GetChar 将立即返回该字符。

下面的示例演示了一种替代方法。它使用KbWait,它提供了非常相似的功能,但需要做更多的工作(即将关键代码转换为字符)。此外,它在按键检查之间实现了 5 毫秒的延迟,这有助于防止按键意外弹跳(将单次按下计为多次按下)。

此示例在左上角打开一个小窗口,在屏幕中央显示当前循环迭代,并等待单击继续。它还记录了按键的次数times

Screen('Preference', 'SkipSyncTests', 2);
[win, rect] = Screen('OpenWindow', 0, [0 0 0], [15 15 400 400]);
Screen('TextSize', win, 20);

answers = cell(1, 5);
times = zeros(1, 5);
ref_time = GetSecs;

for ii = 1:5
    DrawFormattedText(win, num2str(ii), 'center', 'center', [255 255 255]);
    Screen(win, 'Flip');
    [times(ii), key_code] = KbWait;
    answers{ii} = KbName(find(key_code));
    WaitSecs(0.1); %# Wait an extra 100ms for better debouncing
end

times = times - ref_time;

sca;
于 2016-07-13T23:01:25.900 回答