flankerArrowsDemo.m

A copy is also included in PsychBench in <PsychBench folder>/demos, so you can run it from there.

<cdcm>% FLANKER ARROWS EXPERIMENT DEMO<cdcm>
<cdcm>% Coding method<cdcm>
<cdcm>% --------------------------------------------------<cdcm>
 
 
<cdcm>% Eriksen flanker task with left/right arrows. Each trial shows a "target" arrow<cdcm>
<cdcm>% centered on screen and four other "flanker" arrows arranged two on each side<cdcm>
<cdcm>% (see property settings below for sizes and positions). The target can be left<cdcm>
<cdcm>% or right. The flankers can be left, right, or a dash which is just an arrow<cdcm>
<cdcm>% tail extended to the same length as the arrows. All the flankers in a trial<cdcm>
<cdcm>% are the same. The subject responds with left arrow key if the target is left,<cdcm>
<cdcm>% or right arrow key if right, trying to ignore the flankers. A further factor<cdcm>
<cdcm>% is:<cdcm>
<cdcm>%<cdcm>
<cdcm>% Target = left,  Flankers = left   -> CONGRUENT<cdcm>
<cdcm>% Target = right, Flankers = right  -> CONGRUENT<cdcm>
<cdcm>% Target = left,  Flankers = right  -> INCONGRUENT<cdcm>
<cdcm>% Target = right, Flankers = left   -> INCONGRUENT<cdcm>
<cdcm>% Target = left,  Flankers = dash   -> NEUTRAL<cdcm>
<cdcm>% Target = right, Flankers = dash   -> NEUTRAL<cdcm>
<cdcm>%<cdcm>
<cdcm>% Each combination of 2 targets x 3 flankers is tested x3 = 18 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 colors, see flankerColorsDemo.m.<cdcm>
 
 
 
newExperiment
 
 
 
<cdcm>% TASK TRIALS<cdcm>
<cdcm>% ==========<cdcm>
 
<cdcm>% Define 3 arrows and arrow names.<cdcm>
<cdcm>% Arrow and fash files are in <PsychBench folder>/materials/arrow.<cdcm>
arrowFileNames = [
    <cdsm>"arrow_left white.png"<cdsm>
    <cdsm>"arrow_right white.png"<cdsm>
    <cdsm>"arrow_horizontal white.png"<cdsm>
    ];
arrowNames = [
    <cdsm>"left"<cdsm>
    <cdsm>"right"<cdsm>
    <cdsm>"dash"<cdsm>
    ];
 
<cdcm>% 6 trial definitions numbered 1-6: each combination of 2 target arrows x 3 flanker arrows<cdcm>
<cdkm>for<cdkm> n_targetArrow = 1:2
    <cdkm>for<cdkm> n_flankerArrow = 1:3
        <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 picture object below.<cdcm>
 
            trial = trialObject;
 
            trial.info.n_targetArrow = n_targetArrow;
            trial.info.targetArrowName = arrowNames(n_targetArrow);
 
            trial.info.n_flankerArrow = n_flankerArrow;
            trial.info.flankerArrowName = arrowNames(n_flankerArrow);
 
        <cdkm>if<cdkm>      n_flankerArrow == 3
            trial.info.n_condition = 0;
            trial.info.conditionName = <cdsm>"neutral"<cdsm>;
        <cdkm>elseif<cdkm>  n_targetArrow == n_flankerArrow
            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 arrow<cdcm>
        <cdcm>% ---<cdcm>
        target = pictureObject;
 
        <cdcm>% Set file name using arrow #<cdcm>
        target.fileName = arrowFileNames(n_targetArrow);
 
        <cdcm>% 3 deg height<cdcm>
        target.height = 3;
 
        <cdcm>% Default start at trial start; End at response<cdcm>
        target.end.response = true;
        <cdcm>% ---<cdcm>
 
 
        <cdcm>% Flanker arrows<cdcm>
        <cdcm>% ---<cdcm>
            flankers = pictureObject(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).fileName = arrowFileNames(n_flankerArrow);
 
            flankers(n).height = 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> n_targetArrow == 1
            <cdcm>% Target = left -> correct = left (1)<cdcm>
            response.correctResponse = 1;
        <cdkm>else<cdkm>
            <cdcm>% Target = right -> 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, 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(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;
text.text = <cdsm>"Look at the arrow in the middle and press the arrow key corresponding to it: left or right. Try to ignore the shapes 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:6, 3))};
setTrialList(nn)
 
 
 
<cdcm>% You can call "viewExperiment" and "viewExperiment -d" to visualize trials<cdcm>
 
 
 
[results, resultsMatrix] = runExperiment;