2016-06-16 59 views
0

我在MATLAB中使用psychtoolbox,我想讓參與者評估0-9的圖像字符串失真。 我試過使用GetChar,但是當我運行腳本時,它不會等待用戶給出響應,而只是移動到下一個屏幕上。 關於如何解決這個問題的任何建議?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; 

回答

0

有幾件事情怎麼回事:你只是在尋找後您的循環結束按鍵,你也不會存儲按鍵的結果。

GetChar也凌亂(你可能會想打電話FlushEvents清除隊列,否則你可能會遇到(從help GetChar):

如果一個字符在叫的getchar然後getchar函數將 返回之前輸入

下面的例子演示了一種替代方法:它使用了KbWait,它提供了非常類似的功能,還有一些工作(即將鍵碼轉換爲字符)。此外,它在鍵檢查之間實現了5ms的延遲,這有助於防止意外的按鍵彈跳(將單按按多次按鍵計數)。

本示例在左上角打開一個小窗口,在屏幕中心顯示當前循環迭代,並等待單擊繼續。它還記錄了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;