A copy is also included in PsychBench in <PsychBench folder>/demos, so you can run it from there.
<cdcm>% FLANKER COLORS EXPERIMENT DEMO<cdcm>
<cdcm>% Coding method<cdcm>
<cdcm>% --------------------------------------------------<cdcm>
<cdcm>% Eriksen flanker task with colored squares. Each trial shows a "target" square<cdcm>
<cdcm>% centered on screen and four other "flanker" squares arranged two on each side<cdcm>
<cdcm>% (see property settings below for sizes and positions). The target can be red,<cdcm>
<cdcm>% green, blue, or orange. The flankers can be red, green, blue, orange, or gray.<cdcm>
<cdcm>% All the flankers in a trial are the same. The subject responds with left arrow<cdcm>
<cdcm>% key if the target is red OR green, or right arrow key if orange OR gray,<cdcm>
<cdcm>% trying to ignore the flankers. A further factor is:<cdcm>
<cdcm>%<cdcm>
<cdcm>% Target = red/green, Flankers = red/green -> CONGRUENT<cdcm>
<cdcm>% Target = blue/orange, Flankers = blue/orange -> CONGRUENT<cdcm>
<cdcm>% Target = red/green, Flankers = blue/orange -> INCONGRUENT<cdcm>
<cdcm>% Target = blue/orange, Flankers = red/green -> INCONGRUENT<cdcm>
<cdcm>% Target = red/green, Flankers = gray -> NEUTRAL<cdcm>
<cdcm>% Target = blue/orange, Flankers = gray -> NEUTRAL<cdcm>
<cdcm>%<cdcm>
<cdcm>% Each combination of 4 targets x 5 flankers is tested x2 = 40 trials, all in<cdcm>
<cdcm>% random order. The experiment starts with instructions and a prompt to press<cdcm>
<cdcm>% any key to start.<cdcm>
<cdcm>%<cdcm>
<cdcm>% https://en.wikipedia.org/wiki/Eriksen_flanker_task<cdcm>
<cdcm>%<cdcm>
<cdcm>% For the same paradigm except with arrows, see flankerArrowsDemo.m.<cdcm>
newExperiment
<cdcm>% TASK TRIALS<cdcm>
<cdcm>% ==========<cdcm>
<cdcm>% Define 5 RGB colors and color names<cdcm>
colors = [
0.5 0.8 0.5
0.8 0.5 0.5
0.5 0.5 0.5
0.5 0.5 0.8
0.9 0.4 0.2
];
colorNames = [<cdsm>"red"<cdsm> <cdsm>"green"<cdsm> <cdsm>"gray"<cdsm> <cdsm>"blue"<cdsm> <cdsm>"orange"<cdsm>];
<cdcm>% 20 trial definitions numbered 1-20: each combination of 4 target colors x 5 flanker colors<cdcm>
<cdkm>for<cdkm> n_targetColor = [1 2 4 5]
<cdkm>for<cdkm> n_flankerColor = 1:5
<cdcm>% Trial object<cdcm>
<cdcm>% ---<cdcm>
<cdcm>% Set some information to see in experiment results output.<cdcm>
<cdcm>% Do here because it isn't always specific to any one rectangle object below.<cdcm>
trial = trialObject;
trial.info.n_targetColor = n_targetColor;
trial.info.targetColorName = colorNames(n_targetColor);
trial.info.targetColor = colors(n_targetColor,:);
trial.info.n_flankerColor = n_flankerColor;
trial.info.flankerColorName = colorNames(n_flankerColor);
trial.info.flankerColor = colors(n_flankerColor,:);
<cdkm>if<cdkm> n_flankerColor == 3
trial.info.n_condition = 0;
trial.info.conditionName = <cdsm>"neutral"<cdsm>;
<cdkm>elseif<cdkm> ismember(n_targetColor, [1 2]) && ismember(n_flankerColor, [1 2]) || <cdkm>...<cdkm>
ismember(n_targetColor, [3 4]) && ismember(n_flankerColor, [3 4])
trial.info.n_condition = +1;
trial.info.conditionName = <cdsm>"congruent"<cdsm>;
<cdkm>else<cdkm>
trial.info.n_condition = -1;
trial.info.conditionName = <cdsm>"incongruent"<cdsm>;
<cdkm>end<cdkm>
<cdcm>% ---<cdcm>
<cdcm>% Target square<cdcm>
<cdcm>% ---<cdcm>
target = rectangleObject;
<cdcm>% Set color using color #<cdcm>
target.color = colors(n_targetColor,:);
<cdcm>% 3 deg square<cdcm>
target.size = 3;
<cdcm>% Default start at trial start; End at response<cdcm>
target.end.response = true;
<cdcm>% ---<cdcm>
<cdcm>% Flanker squares<cdcm>
<cdcm>% ---<cdcm>
flankers = rectangleObject(4);
<cdcm>% Space 4 deg apart<cdcm>
flankers(1).position = [-8 0];
flankers(2).position = [-4 0];
flankers(3).position = [+4 0];
flankers(4).position = [+8 0];
<cdkm>for<cdkm> n = 1:4
flankers(n).color = colors(n_flankerColor,:);
flankers(n).size = 3;
flankers(n).end.response = true;
<cdkm>end<cdkm>
<cdcm>% ---<cdcm>
<cdcm>% Key press response handler<cdcm>
<cdcm>% ---<cdcm>
response = keyPressObject;
<cdcm>% Listen for left/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 = right.<cdcm>
response.listenKeyNames = [<cdsm>"left"<cdsm> <cdsm>"right"<cdsm>];
<cdcm>% Score correct/incorrect<cdcm>
response.scoreResponse = true;
<cdkm>if<cdkm> ismember(n_targetColor, [1 2])
<cdcm>% Target = red/green -> correct = left (1)<cdcm>
response.correctResponse = 1;
<cdkm>else<cdkm>
<cdcm>% Target = blue/orange -> correct = right (2)<cdcm>
response.correctResponse = 2;
<cdkm>end<cdkm>
<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, correct response, score, latency in results<cdcm>
response.report = [<cdsm>"response"<cdsm> <cdsm>"correctResponse"<cdsm> <cdsm>"responseScore"<cdsm> <cdsm>"responseLatency"<cdsm>];
<cdcm>% ---<cdcm>
<cdcm>% Add trial definition with default numbering (1, 2, 3, ...)<cdcm>
addTrial(target, flankers, response, trial);
<cdkm>end<cdkm>
<cdkm>end<cdkm>
<cdcm>% ==========<cdcm>
<cdcm>% INTRO TRIAL<cdcm>
<cdcm>% ==========<cdcm>
<cdcm>% dialogue object to show text until subject presses any key.<cdcm>
<cdcm>% Can just set text and leave all properties at default.<cdcm>
text = dialogueObject;
<cdcm>% Use in-line formatting options (color)<cdcm>
text.text = <cdsm>"Look at the square in the middle and press the left arrow key if it is <color = [0.5 0.8 0.5]>green<color = [1 1 1]> OR <color = [0.8 0.5 0.5]>red<color = [1 1 1]>, or the right arrow key if it is <color = [0.5 0.5 0.8]>blue<color = [1 1 1]> OR <color = [0.9 0.4 0.2]>orange<color = [1 1 1]>. Try to ignore the squares on the sides. Respond as fast as you can while still trying to be correct. Press any key to begin..."<cdsm>;
<cdcm>% Add trial definition with name "intro"<cdcm>
addTrial(text, <cdsm>"intro"<cdsm>);
<cdcm>% ==========<cdcm>
<cdcm>% Set trial list: Intro, then 2 reps of each trial definition all in random order<cdcm>
nn = {<cdsm>"intro"<cdsm> randomOrder(rep(1:20, 2))};
setTrialList(nn)
<cdcm>% You can call "viewExperiment" and "viewExperiment -d" to visualize trials<cdcm>
[results, resultsMatrix] = runExperiment;