how to code not responding as a correct answer?
Mostrar comentarios más antiguos
For my experiment for certain stimuli I want participants to push the spacebar but for other stimuli I want participants to inhibit their responses. For this I want to be able to code that no keyboard response is correct or rather that a spacebar response to specific stimuli would be incorrect.
How would I go about this?
Respuestas (1)
David Fink
el 26 de Jul. de 2016
If your application is in a figure, you can set a function that is called when a key is pressed. Then, since one of your responses is not to do anything, you will need to have a timer to determine when the next question should be displayed. You could use a global variable to store the user's response
Global variable in script/main function:
userResponse = 'nothing';
Whenever a key is pressed, call myFunction(key) (this code is written in script/main function):
fig = figure();
set(fig,'KeyPressFcn',@(fig,evt) myFunction(evt.Key));
In myFunction(key), you can check what key was pressed:
function myFunction(key)
if strcmp(key,'space')
userResponse = 'space';
else
userResponse = 'other key';
end
end
Declare a timer in the script/main function
questions = ('Press Space', 'Do nothing', ...);
responses = ('space', 'nothing', ...);
q = 0;
tim = timer('BusyMode','drop', ...
'ExecutionMode','fixedrate', ...
'Period',timer_period, ...
'TimerFcn',@myTimerFcn);
start(tim);
The timer function can check what the input was and advance the figure to the next question
function myTimerFcn(~,~)
if q > 0
if strcmp(responses(q),userResponse)
disp('Correct!');
else
disp('Incorrect :(');
end
end
% reset response
userResponse = 'nothing';
% go to next question
q = q + 1;
% Only keep going if there are more questions
if q <= numel(questions)
% display questions(q)
else
stop(tim);
% terminate program
end
end
Categorías
Más información sobre Timing and presenting 2D and 3D stimuli en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!