A copy is also included in PsychBench in <PsychBench folder>/demos, so you can run it from there.
<cdcm>% FEEDBACK DEMO<cdcm>
<cdcm>% Coding method<cdcm>
<cdcm>% --------------------------------------------------<cdcm>
<cdcm>% Each trial shows a prompt "<" or ">" and the subject responds by left/right<cdcm>
<cdcm>% arrow key press with the direction. There is a time limit of 5 sec for<cdcm>
<cdcm>% response. We score response correct/incorrect (true/false), including<cdcm>
<cdcm>% incorrect if no response. Then green "YES" or red "NO" feedback shows for 1<cdcm>
<cdcm>% sec. We run 4 repetitions of each left/right trial for a total of 8 trials,<cdcm>
<cdcm>% all in random order.<cdcm>
<cdcm>% Mark start of experiment script<cdcm>
newExperiment
<cdcm>% 2 trial definitions: 2 directions<cdcm>
<cdkm>for<cdkm> n_direction = [1 2]
<cdcm>% PROMPT TEXT<cdcm>
<cdcm>% ---<cdcm>
prompt = textObject;
<cdcm>% Text to show = "<" or ">" depending on direction for trial<cdcm>
<cdkm>if<cdkm> n_direction == 1
prompt.text = <cdsm>"<"<cdsm>;
<cdkm>else<cdkm>
prompt.text = <cdsm>">"<cdsm>;
<cdkm>end<cdkm>
prompt.fontSize = 1;
<cdcm>% Default start at trial start.<cdcm>
<cdcm>% End when response recorded or at 5 sec duration.<cdcm>
prompt.end(1).response = true;
prompt.end(2).duration = 5;
<cdcm>% ---<cdcm>
<cdcm>% RESPONSE HANDLER<cdcm>
<cdcm>% ---<cdcm>
recorder = keyPressObject;
<cdcm>% Properties below are properties all response handler elements have unless<cdcm>
<cdcm>% otherwose noted.<cdcm>
<cdcm>% Names of keys to listen to.<cdcm>
<cdcm>% You can get these key names using showKey() at the MATLAB command line.<cdcm>
<cdcm>% Response value recorded in record property .response will be number of the name in this list, i.e. 1 = left, 2 = right.<cdcm>
<cdcm>% This property is specific to element type "keyPress".<cdcm>
recorder.listenKeyNames = [<cdsm>"left"<cdsm> <cdsm>"right"<cdsm>];
<cdcm>% Turn on response scoring.<cdcm>
<cdcm>% By default response score = true/false: isequaln(response, correct response).<cdcm>
<cdcm>% Response values 1 = left, 2 = right conveniently match our loop variable "n_direction", so we can just set correct response = that.<cdcm>
recorder.scoreResponse = true;
recorder.correctResponse = n_direction;
<cdcm>% Record "no response" as a response = NaN.<cdcm>
<cdcm>% Do this so it will be scored = false, so incorrect feedback will run on no response.<cdcm>
recorder.recordDefaultResponse = true;
<cdcm>% Set options for if we want to test the experiment by running it in auto response mode:<cdcm>
<cdcm>% Response values generated randomly will be 1/2 (corresponding to left/right in the key names list above).<cdcm>
<cdcm>% Response latency will be random between 0.5-6 sec.<cdcm>
recorder.autoResponse = [1 2];
recorder.autoResponseLatency = [0.5 6];
<cdcm>% Default start at trial start.<cdcm>
<cdcm>% By default will end when records a response.<cdcm>
<cdcm>% Also end at 5 sec duration for time limit.<cdcm>
recorder.end.duration = 5;
<cdcm>% Report all response information.<cdcm>
<cdcm>% Properties all response handler elements have.<cdcm>
recorder.report = [<cdsm>"response"<cdsm> <cdsm>"correctResponse"<cdsm> <cdsm>"responseScore"<cdsm> <cdsm>"responseTime"<cdsm> <cdsm>"responseLatency"<cdsm> <cdsm>"d_responseTime"<cdsm>];
<cdcm>% ---<cdcm>
<cdcm>% FEEDBACK TEXTS<cdcm>
<cdcm>% ---<cdcm>
feedbacks = textObject(2);
<cdcm>% Green "YES" starts at correct response.<cdcm>
feedbacks(1).text = <cdsm>"YES"<cdsm>;
feedbacks(1).color = [0 1 0];
feedbacks(1).fontSize = 1;
feedbacks(1).start.correctResponse = true;
<cdcm>% Red "NO" starts at incorrect response.<cdcm>
feedbacks(2).text = <cdsm>"NO"<cdsm>;
feedbacks(2).color = [1 0 0];
feedbacks(2).fontSize = 1;
feedbacks(2).start.incorrectResponse = true;
<cdcm>% Show for 1 sec<cdcm>
<cdkm>for<cdkm> n = 1:2
feedbacks(n).end.duration = 1;
<cdkm>end<cdkm>
<cdcm>% ---<cdcm>
<cdcm>% Add trial definition with default numbering (1, 2, 3, ...)<cdcm>
addTrial(prompt, recorder, feedbacks);
<cdkm>end<cdkm>
<cdcm>% Trial list: run 4 of each trial definition in random order<cdcm>
nn = randomOrder(rep([1 2], 4));
setTrialList(nn)
<cdcm>% Simulate a subject run<cdcm>
<cdcm>% [results, resultsMatrix] = runExperiment("-a");<cdcm>
<cdcm>% Run<cdcm>
[results, resultsMatrix] = runExperiment;