2016-06-16 18 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を使用しています。これは非常に似た機能を提供しています。もう少し作業すれば(つまり、キーコードをchar )。さらに、キーチェックの間に5msの遅延を実装しているため、偶発的なキーバウンシング(複数のプレスとしての単一のプレスのカウント)を防ぐことができます。

この例では、左上隅に小さなウィンドウを開き、現在のループ反復を画面中央に表示し、1回の印刷が続行されるのを待ちます。また、キー押下の時刻を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; 
関連する問題