A copy is also included in PsychBench in <PsychBench folder>/demos, so you can run it from there.
<cdcm>% STROOP EXPERIMENT DEMO<cdcm>
<cdcm>% Coding method<cdcm>
<cdcm>% --------------------------------------------------<cdcm>
<cdcm>% Stroop task. Each trial shows one of three color words, and the word is shown<cdcm>
<cdcm>% in one of the three colors. The subject responds by key press with the "ink"<cdcm>
<cdcm>% color of the word, not the word itself (left/down/right arrow key = red/green/blue).<cdcm>
<cdcm>% If the Stroop effect applies, we expect more incorrect responses and greater<cdcm>
<cdcm>% response latency for congruent trials where ink color and word match, than for<cdcm>
<cdcm>% incongruent trials where they don't.<cdcm>
<cdcm>%<cdcm>
<cdcm>% 9 conditions: 3 red/green/blue ink x 3 words "red"/"green"/"blue". In each<cdcm>
<cdcm>% block we run 2 repetitions of each of these 9 trials for a total of 18 trials,<cdcm>
<cdcm>% all in random order. We run 2 blocks. We also run an intro trial, a break<cdcm>
<cdcm>% trial between the blocks, and an outro trial.<cdcm>
<cdcm>%<cdcm>
<cdcm>% https://en.wikipedia.org/wiki/Stroop_effect<cdcm>
<cdcm>%<cdcm>
<cdcm>% For a more classic implementation where the subject responds verbally, see stroopSoundDemo.m.<cdcm>
newExperiment
<cdcm>% TASK TRIALS<cdcm>
<cdcm>% ==========<cdcm>
<cdcm>% Define 3 words<cdcm>
words = [
<cdsm>"RED"<cdsm>
<cdsm>"GREEN"<cdsm>
<cdsm>"BLUE"<cdsm>
];
<cdcm>% Define 3 ink colors (RGB)<cdcm>
colors = [
1 0 0 <cdcm>% red<cdcm>
0 1 0 <cdcm>% green<cdcm>
0 0 1 <cdcm>% blue<cdcm>
];
<cdcm>% 9 trial definitions numbered 1-9: 3 words x 3 ink colors<cdcm>
<cdkm>for<cdkm> w = 1:3
<cdkm>for<cdkm> i = 1:3
<cdcm>% Text<cdcm>
<cdcm>% ---<cdcm>
text = textObject;
<cdcm>% Set word and display color using word #, color #<cdcm>
text.text = words(w);
text.color = colors(i,:);
<cdcm>% Make this text a bit bigger than default (deg)<cdcm>
text.fontSize = 1.5;
<cdcm>% Default start at trial start; End at response<cdcm>
text.end.response = true;
<cdcm>% See word #, ink color #, congruent (true/false), text, color in results<cdcm>
text.info.n_word = w;
text.info.n_ink = i;
<cdcm>% Congruent if word # matches ink color #<cdcm>
text.info.congruent = w == i;
text.report = [<cdsm>"text"<cdsm> <cdsm>"color"<cdsm>];
<cdcm>% ---<cdcm>
<cdcm>% Key press response<cdcm>
<cdcm>% ---<cdcm>
response = keyPressObject;
<cdcm>% Listen for left/down/right arrow keys.<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 = down, 3 = right.<cdcm>
response.listenKeyNames = [<cdsm>"left"<cdsm> <cdsm>"down"<cdsm> <cdsm>"right"<cdsm>];
<cdcm>% Score correct/incorrect.<cdcm>
<cdcm>% Response values 1 = left, 2 = down, 3 = right conveniently match our loop variable "c", so we can just set correct response = that.<cdcm>
response.scoreResponse = true;
response.correctResponse = i;
<cdcm>% Default start at trial start.<cdcm>
<cdcm>% By default keyPress elements end when they record a response -> don't need to set .end.<cdcm>
<cdcm>% See response, score, latency in results<cdcm>
response.report = [<cdsm>"response"<cdsm> <cdsm>"responseScore"<cdsm> <cdsm>"responseLatency"<cdsm>];
<cdcm>% ---<cdcm>
<cdcm>% Add trial definition with default numbering (1, 2, 3, ...)<cdcm>
addTrial(text, response);
<cdkm>end<cdkm>
<cdkm>end<cdkm>
<cdcm>% ==========<cdcm>
<cdcm>% INTRO, BREAK, OUTRO TRIALS<cdcm>
<cdcm>% ==========<cdcm>
<cdcm>% Intro.<cdcm>
<cdcm>% dialogue object to show text until subject presses any key.<cdcm>
text = dialogueObject;
<cdcm>% Each string in the array is a new line.<cdcm>
<cdcm>% Use in-line formatting options (color).<cdcm>
text.text = [
<cdsm>"Press the color of the ink, not what the word says. Respond as fast as possible while still trying to be correct."<cdsm>
<cdsm>""<cdsm>
<cdsm>"<color = [1 0 0]>LEFT = red ink"<cdsm>
<cdsm>"<color = [0 1 0]>DOWN = green ink"<cdsm>
<cdsm>"<color = [0 0 1]>RIGHT = blue ink<color = [0 0 0]>"<cdsm>
<cdsm>""<cdsm>
<cdsm>"Press any key to begin..."<cdsm>
];
<cdcm>% Change font color from default white to black cause we will use a white background<cdcm>
text.color = [0 0 0];
<cdcm>% Align left instead of center<cdcm>
text.alignment = <cdsm>"l"<cdsm>;
<cdcm>%Add trial definition with name "intro"<cdcm>
addTrial(text, <cdsm>"intro"<cdsm>);
<cdcm>%Break trial.<cdcm>
<cdcm>%Use same object from above, just change the text.<cdcm>
text.text = <cdsm>"Take a break! Press any key when you are ready to continue..."<cdsm>;
<cdcm>% Add trial definition with name "break"<cdcm>
addTrial(text, <cdsm>"break"<cdsm>);
<cdcm>%Outro trial<cdcm>
text.text = <cdsm>"Done--thank-you!"<cdsm>;
addTrial(text, <cdsm>"outro"<cdsm>);
<cdcm>% ==========<cdcm>
<cdcm>% Set trial list:<cdcm>
<cdcm>%<cdcm>
<cdcm>% - intro trial<cdcm>
<cdcm>% - 2 repetitions of each task trial definition in random order<cdcm>
<cdcm>% - break trial<cdcm>
<cdcm>% - 2 repetitions of each task trial definition in random order<cdcm>
<cdcm>% - outro trial<cdcm>
<cdcm>%<cdcm>
<cdcm>% Random order just to randomize left/right<cdcm>
nn = {<cdsm>"intro"<cdsm> randomOrder(rep(1:9, 2)) <cdsm>"break"<cdsm> randomOrder(rep(1:9, 2)) <cdsm>"outro"<cdsm>};
setTrialList(nn)
<cdcm>% Set experiment background color to white in an experiment object<cdcm>
experiment = experimentObject;
experiment.backColor = [1 1 1];
addToExperiment(experiment)
<cdcm>% You can call "viewExperiment" and "viewExperiment -d" to visualize trials<cdcm>
[results, resultsMatrix] = runExperiment;