Skip to content
StateSwitch_practice_170829.m 32.2 KiB
Newer Older
Julian Kosciessa's avatar
Julian Kosciessa committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
%_______________________________________________________________________
%
% Run random dot motion experiment defined in createDotInfo
%_______________________________________________________________________
%
% Input
%
% expInfo | experiment configuration (struct)
%    subj | identifier of subject (string)
% condSet | conditions (cell array of strings)
%_______________________________________________________________________
%
% 170707    | updated palamedes to take in more inputs
% 170821    | adapted to state switch variant; no more threshold estimation

function StateSwitch_practice_170829(expInfo, setup)

  %%
  %% sanitize function parameters
  %%
  if nargin == 0
    eval('help dotsExperiment')
    return
  end

  if not(exist('expInfo','var'))
    error('Missing input: expInfo')
  elseif isempty(expInfo) || not(isstruct(expInfo))
    error('Invalid input: expInfo (requires non-empty struct)')
  end

  if not(isfield(expInfo,'deployed'))
    expInfo.deployed = true;
  end

  %%
  %% for saving behavioural data
  %%

  sessionFile = [setup.subjectsPath, setup.subj, '_Practice_', datestr(now, 'yymmdd_HHMM'), '.mat'];
    
  %%
  %% prepare presentation
  %%
  displayList = Screen('Screens'); % There appears to be a problem in DEBUG mode.
  displayIdx = displayList(setup.disp);
  KbName('UnifyKeyNames'); % use portable key naming scheme
  oldVerbosityLevel = Screen('Preference', 'Verbosity', 2); % show errors and warning

    if setup.DEBUG == 1
        Screen('Preference', 'SkipSyncTests', 1);
        PsychDebugWindowConfiguration(0, setup.opacity);
    else
        clear Screen; %PsychDebugWindowConfiguration([], 1);
    end

  try

    %%
    %% prepare canvas
    %%
    screenInfo = openExperiment(50,50,displayIdx); clc; % open drawing canvas
    if numel(Screen('screens')) == 1 || expInfo.deployed
      HideCursor(screenInfo.curWindow);
    end
    Screen('TextFont', screenInfo.curWindow, 'Helvetica');
    Screen('TextSize', screenInfo.curWindow, 20);
    Screen('TextStyle', screenInfo.curWindow, 0); % regular
    Screen('TextColor', screenInfo.curWindow, 255); % white
    ifi = Screen('GetFlipInterval', screenInfo.curWindow); % Query the frame duration
    
    % get experimenter and subject keyboards
    keyboardIndices = GetKeyboardIndices;
    if setup.keyB == 1 % use primary keyboard for subject and experimenter
        screenInfo.keyboard_sub = keyboardIndices(1);
        screenInfo.keyboard_exp = keyboardIndices(1);
    elseif setup.keyB == 2
        screenInfo.keyboard_sub = min(keyboardIndices);
        screenInfo.keyboard_exp = max(keyboardIndices);
    else disp('Check setup: only 1 or 2 keyboards supported.');
    end
    
    ResultMat = [];
    
    ExperimentProtocol = cell(0);
    ExperimentProtocol = [ExperimentProtocol; {'SessionOnset'}, {GetSecs}, {[]}, {[]}, {[]}, {NaN},{NaN},{NaN} {[]}];

    %% Intro slide

    if strcmp(setup.task, 'dynamic')
        DrawFormattedText(screenInfo.curWindow, '\n Willkommen bei der StateSwitch Aufgabe \n\n Im folgenden werden Sie Vierecksmuster sehen, die verschiedene Charakteristika aufweisen: \n\n Farbton \n\n Bewegungsrichtung \n\n Gre \n\n Sttigung \n\n\n Zunchst werden wir die Attribute einzeln bearbeiten. \n\n Bitte geben Sie an, von welcher der beiden Optionen mehr prsentiert wurde. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center');
    elseif strcmp(setup.task, 'words')
        DrawFormattedText(screenInfo.curWindow, '\n Willkommen bei der StateSwitch Aufgabe \n\n Im folgenden werden Ihnen Wrter prsentiert, zu denen verschiedene Fragen gestellt werden: \n\n Handelt es sich um ein TIER? \n\n Ist das Wort EINSILBIG? \n\n Ist die Buchstabenanzahl GERADE? \n\n Beinhaltet das Wort mind. ein H? \n\n Zunchst werden wir die Fragen einzeln ben. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center');
    elseif strcmp(setup.task, 'visual')
        DrawFormattedText(screenInfo.curWindow, '\n Willkommen bei der StateSwitch Aufgabe \n\n Im folgenden werden Ihnen visuelle Symbole prsentiert, zu denen verschiedene Fragen gestellt werden: \n\n Welche FARBE hat es? \n\n Gibt es ein MUSTER? \n\n Gibt es einen RAND? \n\n Welche FORM hat es? \n\n Zunchst werden wir die Fragen einzeln ben. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center');
    end
    Screen('Flip', screenInfo.curWindow);
    disp('Experimenter input required: Intro Example (1/2)');
    % wait for experimenter to resume session
    while true
        [exitSession, resumeSession] = checkKeys_byKeyB(expInfo, screenInfo.keyboard_exp);
    if resumeSession
        break
    elseif exitSession
        closeExperiment;
        return
    end
    end
    
    %% Instruction 2
    
    if strcmp(setup.task, 'dynamic')
        DrawFormattedText(screenInfo.curWindow, 'Wir beginnen mit der Farbe. \n\n\n Falls die grnen Punkte berwiegen, drcken Sie die linke Taste. \n\n Falls die roten Punkte berwiegen, dcken Sie die rechte Taste. \n\n\n Im Anschluss an Ihre Antwort erhalten Sie eine Rckmeldung. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center');
    elseif strcmp(setup.task, 'words')
        DrawFormattedText(screenInfo.curWindow, 'Wir beginnen mit der Frage, ob das Wort ein Tier benennt. \n\n\n Falls NEIN, drcken Sie die linke Taste. \n\n Falls JA, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    elseif strcmp(setup.task, 'visual')
        DrawFormattedText(screenInfo.curWindow, 'Wir beginnen mit der Frage, welche Farbe das Muster besitzt. \n\n\n Falls GRN, drcken Sie die linke Taste. \n\n Falls ROT, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    end
    Screen('Flip', screenInfo.curWindow);
    disp('Experimenter input required: Intro Coulour --> Start Colour presentation');
    pause(1);
    % wait for experimenter to resume session
    while true
        [exitSession, resumeSession] = checkKeys_byKeyB(expInfo, screenInfo.keyboard_exp);
        if resumeSession
            break
        elseif exitSession
            closeExperiment;
            return
        end
    end
    
    %% 1st dimension
    
    % intiate parameters
    DisplayInfo.CombPositionByTrial = [];
    DisplayInfo.CombSamples = [];
    ResultMat = [];
    % get a single run containing only the target attribute
    expInfo = [];
    if strcmp(setup.task, 'dynamic')
        expInfo = StateSwitch_createExpInfo_dynamic_TEST_170829(1);
    elseif strcmp(setup.task, 'words')
        expInfo = StateSwitch_createExpInfo_words_TEST_170829(1);
    elseif strcmp(setup.task, 'visual')
        expInfo = StateSwitch_createExpInfo_visual_TEST_170829(1);
    end
    expInfo.deployed = true;
    expInfo.feedback = 1;
    
    for indRun = 1
        Timing.RunInitiation = GetSecs();
        Timing.lastTiming = 'NaN';
        for indBlock = 1
            % initialize state cues of current condition
            if strcmp(setup.task, 'dynamic')
                StateSwitch_addSurroundingCues_dynamic(expInfo, screenInfo, 1, 1, 1);
            elseif strcmp(setup.task, 'words')
                StateSwitch_addSurroundingCues_words(expInfo, screenInfo, 1, 1, 1);
            elseif strcmp(setup.task, 'visual')
                StateSwitch_addSurroundingCues_visual(expInfo, screenInfo, 1, 1, 1);
            end
            oldTextSize = Screen('TextSize', screenInfo.curWindow, 30);
            DrawFormattedText(screenInfo.curWindow, ['relevante Attribute: ', num2str(expInfo.StateOrderRun{indRun}(indBlock,1))], 'center', 'center');
            Screen('TextSize', screenInfo.curWindow, oldTextSize); clear oldTextSize;

            % ####### Block cue onset #####
            if strcmp(expInfo.timing, 'absolute') || strcmp(expInfo.timing, 'relativeITI')
                flipWhen = Timing.RunInitiation+(indBlock-1)*expInfo.durBlockOnset+(indBlock-1)*expInfo.blockLengthDim*expInfo.trialDuration.all+(indBlock-1)*expInfo.durReward-(ifi/2);
            elseif strcmp(expInfo.timing, 'relative')
                if strcmp(Timing.lastTiming, 'NaN')
                    flipWhen = 0;
                elseif strcmp(Timing.lastTiming, 'ITI')
                    flipWhen = Timing.ITIOnset+expInfo.durITI-(ifi/2);
                end                
            end
            Timing.BlockInitiation = Screen('Flip', screenInfo.curWindow, flipWhen);
            Timing.lastTiming = 'BlockCue';
            ExperimentProtocol = [ExperimentProtocol; {'BlockInitiation'}, {Timing.BlockInitiation}, {[]}, {[]}, {[]}, {indRun}, {indBlock}, {[]}, {[]}];
            for indTrial = 1:setup.pr.ntrials_single
                Timing.TrialInitiation = GetSecs();
                ExperimentProtocol = [ExperimentProtocol; {'TrialInitiation'}, {Timing.TrialInitiation}, {[]}, {[]}, {[]}, {indRun}, {indBlock}, {[]}, {[]}];
                if strcmp(setup.task, 'dynamic')
                    % create fixation
                    targets = makeDotTargets(screenInfo, expInfo); % initialize targets
                    %showTargets(screenInfo, targets, 1);
                    [~, expInfo, ExperimentProtocol,ResultMat,DisplayInfo,Timing] = ...
                    StateSwitch_trialPresentation_dynamic_170829(screenInfo, expInfo, targets, indRun, indBlock, indTrial, ...
                    ExperimentProtocol,ResultMat,DisplayInfo,Timing,setup);
                elseif strcmp(setup.task, 'words') || strcmp(setup.task, 'visual')
                    [~, expInfo, ExperimentProtocol,ResultMat,DisplayInfo,Timing] = ...
                    StateSwitch_trialPresentation_words_visual_170829(screenInfo, expInfo, [], indRun, indBlock, indTrial, ...
                    ExperimentProtocol,ResultMat,DisplayInfo,Timing,setup);
                end
            end
        end
    end
    
    Results{1,1} = expInfo;
    Results{2,1} = ExperimentProtocol;
    Results{3,1} = ResultMat;
    Results{4,1} = DisplayInfo;
    
    %% Instruction
    
    if strcmp(setup.task, 'dynamic')
        DrawFormattedText(screenInfo.curWindow, 'Als nchstes die Bewegungsrichtung. \n\n\n Falls die Bewegung nach links berwiegt, drcken Sie die linke Taste. \n\n Falls die Bewegung nach rechts berwiegt, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    elseif strcmp(setup.task, 'words')
        DrawFormattedText(screenInfo.curWindow, 'Als nchstes folgt die Frage, ob das Wort einsilbig ist. \n\n\n Falls NEIN, drcken Sie die linke Taste. \n\n Falls JA, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    elseif strcmp(setup.task, 'visual')
        DrawFormattedText(screenInfo.curWindow, 'Als nchstes folgt die Frage, ob das Symbol ein Muster beinhaltet. \n\n\n Falls NEIN, drcken Sie die linke Taste. \n\n Falls JA, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    end
    Screen('Flip', screenInfo.curWindow);    
    disp('Experimenter input required: Intro Direction --> Start Direction presentation');

    pause(1);

    % wait for experimenter to resume session
    while true
        [exitSession, resumeSession] = checkKeys_byKeyB(expInfo, screenInfo.keyboard_exp);
        if resumeSession
            break
        elseif exitSession
            closeExperiment;
            return
        end
    end
    
    %% 2nd dimension
    
    % intiate parameters
    DisplayInfo.CombPositionByTrial = [];
    DisplayInfo.CombSamples = [];
    ResultMat = [];
    % get a single run containing only the target attribute
    expInfo = [];
    if strcmp(setup.task, 'dynamic')
        expInfo = StateSwitch_createExpInfo_dynamic_TEST_170829(2);
    elseif strcmp(setup.task, 'words')
        expInfo = StateSwitch_createExpInfo_words_TEST_170829(2);
    elseif strcmp(setup.task, 'visual')
        expInfo = StateSwitch_createExpInfo_visual_TEST_170829(2);
    end
    expInfo.deployed = true;
    expInfo.feedback = 1;
    
    for indRun = 1
        Timing.RunInitiation = GetSecs();
        Timing.lastTiming = 'NaN';
        for indBlock = 1
            % initialize state cues of current condition
            if strcmp(setup.task, 'dynamic')
                StateSwitch_addSurroundingCues_dynamic(expInfo, screenInfo, 1, 1, 1);
            elseif strcmp(setup.task, 'words')
                StateSwitch_addSurroundingCues_words(expInfo, screenInfo, 1, 1, 1);
            elseif strcmp(setup.task, 'visual')
                StateSwitch_addSurroundingCues_visual(expInfo, screenInfo, 1, 1, 1);
            end
            oldTextSize = Screen('TextSize', screenInfo.curWindow, 30);
            DrawFormattedText(screenInfo.curWindow, ['relevante Attribute: ', num2str(expInfo.StateOrderRun{indRun}(indBlock,1))], 'center', 'center');
            Screen('TextSize', screenInfo.curWindow, oldTextSize); clear oldTextSize;

            % ####### Block cue onset #####
            if strcmp(expInfo.timing, 'absolute') || strcmp(expInfo.timing, 'relativeITI')
                flipWhen = Timing.RunInitiation+(indBlock-1)*expInfo.durBlockOnset+(indBlock-1)*expInfo.blockLengthDim*expInfo.trialDuration.all+(indBlock-1)*expInfo.durReward-(ifi/2);
            elseif strcmp(expInfo.timing, 'relative')
                if strcmp(Timing.lastTiming, 'NaN')
                    flipWhen = 0;
                elseif strcmp(Timing.lastTiming, 'ITI')
                    flipWhen = Timing.ITIOnset+expInfo.durITI-(ifi/2);
                end                
            end
            Timing.BlockInitiation = Screen('Flip', screenInfo.curWindow, flipWhen);
            Timing.lastTiming = 'BlockCue';
            ExperimentProtocol = [ExperimentProtocol; {'BlockInitiation'}, {Timing.BlockInitiation}, {[]}, {[]}, {[]}, {indRun}, {indBlock}, {[]}, {[]}];
            for indTrial = 1:setup.pr.ntrials_single
                Timing.TrialInitiation = GetSecs();
                ExperimentProtocol = [ExperimentProtocol; {'TrialInitiation'}, {Timing.TrialInitiation}, {[]}, {[]}, {[]}, {indRun}, {indBlock}, {[]}, {[]}];
                if strcmp(setup.task, 'dynamic')
                    % create fixation
                    targets = makeDotTargets(screenInfo, expInfo); % initialize targets
                    %showTargets(screenInfo, targets, 1);
                    [~, expInfo, ExperimentProtocol,ResultMat,DisplayInfo,Timing] = ...
                    StateSwitch_trialPresentation_dynamic_170829(screenInfo, expInfo, targets, indRun, indBlock, indTrial, ...
                    ExperimentProtocol,ResultMat,DisplayInfo,Timing,setup);
                elseif strcmp(setup.task, 'words') || strcmp(setup.task, 'visual')
                    [~, expInfo, ExperimentProtocol,ResultMat,DisplayInfo,Timing] = ...
                    StateSwitch_trialPresentation_words_visual_170829(screenInfo, expInfo, [], indRun, indBlock, indTrial, ...
                    ExperimentProtocol,ResultMat,DisplayInfo,Timing,setup);
                end
            end
        end
    end    
    Results{1,2} = expInfo;
    Results{2,2} = ExperimentProtocol;
    Results{3,2} = ResultMat;
    Results{4,2} = DisplayInfo;
    
    %% Instruction
    
    if strcmp(setup.task, 'dynamic')
        DrawFormattedText(screenInfo.curWindow, 'Als nchstes die Punktgre. \n\n\n Falls die kleineren Punkte berwiegen, drcken Sie die linke Taste. \n\n Falls die greren Punkte berwiegen, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    elseif strcmp(setup.task, 'words')
        DrawFormattedText(screenInfo.curWindow, 'Als nchstes folgt die Frage, ob das Wort eine gerade Anzahl an Buchstaben aufweist. \n\n\n Falls NEIN, drcken Sie die linke Taste. \n\n Falls JA, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    elseif strcmp(setup.task, 'visual')
        DrawFormattedText(screenInfo.curWindow, 'Als nchstes folgt die Frage, ob das Symbol einen weien Rand besitzt. \n\n\n Falls NEIN, drcken Sie die linke Taste. \n\n Falls JA, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    end
    Screen('Flip', screenInfo.curWindow);
    disp('Experimenter input required: Intro Size --> Start Size presentation');

    pause(1);
    
    % wait for experimenter to resume session
    while true
        [exitSession, resumeSession] = checkKeys_byKeyB(expInfo, screenInfo.keyboard_exp);
    if resumeSession
        break
    elseif exitSession
        closeExperiment;
        return
    end
    end
    
    %% 3rd dimension
    
    % intiate parameters
    DisplayInfo.CombPositionByTrial = [];
    DisplayInfo.CombSamples = [];
    ResultMat = [];
    % get a single run containing only the target attribute
    expInfo = [];
    if strcmp(setup.task, 'dynamic')
        expInfo = StateSwitch_createExpInfo_dynamic_TEST_170829(3);
    elseif strcmp(setup.task, 'words')
        expInfo = StateSwitch_createExpInfo_words_TEST_170829(3);
    elseif strcmp(setup.task, 'visual')
        expInfo = StateSwitch_createExpInfo_visual_TEST_170829(3);
    end
    expInfo.deployed = true;
    expInfo.feedback = 1;
    
    for indRun = 1
        Timing.RunInitiation = GetSecs();
        Timing.lastTiming = 'NaN';
        for indBlock = 1
            % initialize state cues of current condition
            if strcmp(setup.task, 'dynamic')
                StateSwitch_addSurroundingCues_dynamic(expInfo, screenInfo, 1, 1, 1);
            elseif strcmp(setup.task, 'words')
                StateSwitch_addSurroundingCues_words(expInfo, screenInfo, 1, 1, 1);
            elseif strcmp(setup.task, 'visual')
                StateSwitch_addSurroundingCues_visual(expInfo, screenInfo, 1, 1, 1);
            end
            oldTextSize = Screen('TextSize', screenInfo.curWindow, 30);
            DrawFormattedText(screenInfo.curWindow, ['relevante Attribute: ', num2str(expInfo.StateOrderRun{indRun}(indBlock,1))], 'center', 'center');
            Screen('TextSize', screenInfo.curWindow, oldTextSize); clear oldTextSize;

            % ####### Block cue onset #####
            if strcmp(expInfo.timing, 'absolute') || strcmp(expInfo.timing, 'relativeITI')
                flipWhen = Timing.RunInitiation+(indBlock-1)*expInfo.durBlockOnset+(indBlock-1)*expInfo.blockLengthDim*expInfo.trialDuration.all+(indBlock-1)*expInfo.durReward-(ifi/2);
            elseif strcmp(expInfo.timing, 'relative')
                if strcmp(Timing.lastTiming, 'NaN')
                    flipWhen = 0;
                elseif strcmp(Timing.lastTiming, 'ITI')
                    flipWhen = Timing.ITIOnset+expInfo.durITI-(ifi/2);
                end                
            end
            Timing.BlockInitiation = Screen('Flip', screenInfo.curWindow, flipWhen);
            Timing.lastTiming = 'BlockCue';
            ExperimentProtocol = [ExperimentProtocol; {'BlockInitiation'}, {Timing.BlockInitiation}, {[]}, {[]}, {[]}, {indRun}, {indBlock}, {[]}, {[]}];
            for indTrial = 1:setup.pr.ntrials_single
                Timing.TrialInitiation = GetSecs();
                ExperimentProtocol = [ExperimentProtocol; {'TrialInitiation'}, {Timing.TrialInitiation}, {[]}, {[]}, {[]}, {indRun}, {indBlock}, {[]}, {[]}];
                if strcmp(setup.task, 'dynamic')
                    % create fixation
                    targets = makeDotTargets(screenInfo, expInfo); % initialize targets
                    %showTargets(screenInfo, targets, 1);
                    [~, expInfo, ExperimentProtocol,ResultMat,DisplayInfo,Timing] = ...
                    StateSwitch_trialPresentation_dynamic_170829(screenInfo, expInfo, targets, indRun, indBlock, indTrial, ...
                    ExperimentProtocol,ResultMat,DisplayInfo,Timing,setup);
                elseif strcmp(setup.task, 'words') || strcmp(setup.task, 'visual')
                    [~, expInfo, ExperimentProtocol,ResultMat,DisplayInfo,Timing] = ...
                    StateSwitch_trialPresentation_words_visual_170829(screenInfo, expInfo, [], indRun, indBlock, indTrial, ...
                    ExperimentProtocol,ResultMat,DisplayInfo,Timing,setup);
                end
            end
        end
    end
    
    Results{1,3} = expInfo;
    Results{2,3} = ExperimentProtocol;
    Results{3,3} = ResultMat;
    Results{4,3} = DisplayInfo;
    
    %% Instruction
    
    if strcmp(setup.task, 'dynamic')
        DrawFormattedText(screenInfo.curWindow, 'Zuletzt die Sttigung. \n\n\n Falls die ungesttigteren Punkte berwiegen, drcken Sie die linke Taste. \n\n Falls die gesttigteren Punkte berwiegen, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    elseif strcmp(setup.task, 'words')
        DrawFormattedText(screenInfo.curWindow, 'Zuletzt die Frage, ob das Wort mind. ein H beinhaltet. \n\n\n Falls NEIN, drcken Sie die linke Taste. \n\n Falls JA, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    elseif strcmp(setup.task, 'visual')
        DrawFormattedText(screenInfo.curWindow, 'Zuletzt die Frage, nach der Form. \n\n\n Falls KREIS, drcken Sie die linke Taste. \n\n Falls RECHTECK, dcken Sie die rechte Taste. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    end
    Screen('Flip', screenInfo.curWindow);
    disp('Experimenter input required: Intro Luminance --> Start Luminance presentation');

    pause(1);
    
    % wait for experimenter to resume session
    while true
        [exitSession, resumeSession] = checkKeys_byKeyB(expInfo, screenInfo.keyboard_exp);
    if resumeSession
        break
    elseif exitSession
        closeExperiment;
        return
    end
    end
    
     %% 4th dimension
    
    % intiate parameters
    DisplayInfo.CombPositionByTrial = [];
    DisplayInfo.CombSamples = [];
    ResultMat = [];
    % get a single run containing only the target attribute
    expInfo = [];
    if strcmp(setup.task, 'dynamic')
        expInfo = StateSwitch_createExpInfo_dynamic_TEST_170829(4);
    elseif strcmp(setup.task, 'words')
        expInfo = StateSwitch_createExpInfo_words_TEST_170829(4);
    elseif strcmp(setup.task, 'visual')
        expInfo = StateSwitch_createExpInfo_visual_TEST_170829(4);
    end
    expInfo.deployed = true;
    expInfo.feedback = 1;
    
    for indRun = 1
        Timing.RunInitiation = GetSecs();
        Timing.lastTiming = 'NaN';
        for indBlock = 1
            % initialize state cues of current condition
            if strcmp(setup.task, 'dynamic')
                StateSwitch_addSurroundingCues_dynamic(expInfo, screenInfo, 1, 1, 1);
            elseif strcmp(setup.task, 'words')
                StateSwitch_addSurroundingCues_words(expInfo, screenInfo, 1, 1, 1);
            elseif strcmp(setup.task, 'visual')
                StateSwitch_addSurroundingCues_visual(expInfo, screenInfo, 1, 1, 1);
            end
            oldTextSize = Screen('TextSize', screenInfo.curWindow, 30);
            DrawFormattedText(screenInfo.curWindow, ['relevante Attribute: ', num2str(expInfo.StateOrderRun{indRun}(indBlock,1))], 'center', 'center');
            Screen('TextSize', screenInfo.curWindow, oldTextSize); clear oldTextSize;

            % ####### Block cue onset #####
            if strcmp(expInfo.timing, 'absolute') || strcmp(expInfo.timing, 'relativeITI')
                flipWhen = Timing.RunInitiation+(indBlock-1)*expInfo.durBlockOnset+(indBlock-1)*expInfo.blockLengthDim*expInfo.trialDuration.all+(indBlock-1)*expInfo.durReward-(ifi/2);
            elseif strcmp(expInfo.timing, 'relative')
                if strcmp(Timing.lastTiming, 'NaN')
                    flipWhen = 0;
                elseif strcmp(Timing.lastTiming, 'ITI')
                    flipWhen = Timing.ITIOnset+expInfo.durITI-(ifi/2);
                end                
            end
            Timing.BlockInitiation = Screen('Flip', screenInfo.curWindow, flipWhen);
            Timing.lastTiming = 'BlockCue';
            ExperimentProtocol = [ExperimentProtocol; {'BlockInitiation'}, {Timing.BlockInitiation}, {[]}, {[]}, {[]}, {indRun}, {indBlock}, {[]}, {[]}];
            for indTrial = 1:setup.pr.ntrials_single
                Timing.TrialInitiation = GetSecs();
                ExperimentProtocol = [ExperimentProtocol; {'TrialInitiation'}, {Timing.TrialInitiation}, {[]}, {[]}, {[]}, {indRun}, {indBlock}, {[]}, {[]}];
                if strcmp(setup.task, 'dynamic')
                    % create fixation
                    targets = makeDotTargets(screenInfo, expInfo); % initialize targets
                    %showTargets(screenInfo, targets, 1);
                    [~, expInfo, ExperimentProtocol,ResultMat,DisplayInfo,Timing] = ...
                    StateSwitch_trialPresentation_dynamic_170829(screenInfo, expInfo, targets, indRun, indBlock, indTrial, ...
                    ExperimentProtocol,ResultMat,DisplayInfo,Timing,setup);
                elseif strcmp(setup.task, 'words') || strcmp(setup.task, 'visual')
                    [~, expInfo, ExperimentProtocol,ResultMat,DisplayInfo,Timing] = ...
                    StateSwitch_trialPresentation_words_visual_170829(screenInfo, expInfo, [], indRun, indBlock, indTrial, ...
                    ExperimentProtocol,ResultMat,DisplayInfo,Timing,setup);
                end
            end
        end
    end
    
    Results{1,4} = expInfo;
    Results{2,4} = ExperimentProtocol;
    Results{3,4} = ResultMat;
    Results{4,4} = DisplayInfo;
    
    %% Instruction 1
    
    DrawFormattedText(screenInfo.curWindow, 'Nun kennen Sie alle Attribute. \n\n  Diese werden Ihnen im Folgenden gemeinsam prsentiert. \n\n Bitte geben Sie wie zuvor an, welche der beiden Optionen eines Attributs berwiegend vorhanden ist. \n\n Das relevante Attribut wird Ihnen dabei nach der Prsentation prsentiert. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    Screen('Flip', screenInfo.curWindow);
    disp('Experimenter input required: Intro Realistic 1/3');

    pause(1);
    
    % wait for experimenter to resume session
    while true
        [exitSession, resumeSession] = checkKeys_byKeyB(expInfo, screenInfo.keyboard_exp);
    if resumeSession
        break
    elseif exitSession
        closeExperiment;
        return
    end
    end
    
    %% Instruction 1
    
    DrawFormattedText(screenInfo.curWindow, 'Vor jedem Durchgang erfahren Sie, welche Attribute abgefragt werden knnen. \n\n Sie werden nun nicht mehr erfahren, ob Ihre Antworten korrekt waren. \n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
    Screen('Flip', screenInfo.curWindow);
    disp('Experimenter input required: Intro Realistic 2/3');

    pause(1);
    
    % wait for experimenter to resume session
    while true
        [exitSession, resumeSession] = checkKeys_byKeyB(expInfo, screenInfo.keyboard_exp);
    if resumeSession
        break
    elseif exitSession
        closeExperiment;
        return
    end
    end
    
    %% Instruction 2
    
    if expInfo.durConf > 0
        DrawFormattedText(screenInfo.curWindow, 'Zudem bitten wir Sie im Anschluss um eine Einschtzung, wie sicher Sie sich bei der Entscheidung sind. \n\n  Bitte drcken Sie dann die linke Taste, falls sie sich eher unsicher sind. \n\n Bitte drcken Sie dann die rechte Taste, falls sie sich eher sicher sind. \n\n\n Bitte rechte Taste zum Fortfahren drcken.', 'center', 'center', [255 255 255]);
        Screen('Flip', screenInfo.curWindow);
        disp('Experimenter input required: Intro Realistic 3/3 --> Start Realistic cueing, no feedback');

        pause(1);

        % wait for experimenter to resume session
        while true
            [exitSession, resumeSession] = checkKeys_byKeyB(expInfo, screenInfo.keyboard_exp);
        if resumeSession
            break
        elseif exitSession
            closeExperiment;
            return
        end
        end
    end
    
    %% realistic without cue
    
    % intiate parameters
    DisplayInfo.CombPositionByTrial = [];
    DisplayInfo.CombSamples = [];
    ResultMat = [];
    % get a single run containing only the target attribute
    expInfo = [];
    if strcmp(setup.task, 'dynamic')
        expInfo = StateSwitch_createExpInfo_dynamic_TEST_170829(5);
    elseif strcmp(setup.task, 'words')
        expInfo = StateSwitch_createExpInfo_words_TEST_170829(5);
    elseif strcmp(setup.task, 'visual')
        expInfo = StateSwitch_createExpInfo_visual_TEST_170829(5);
    end
    expInfo.deployed = true;
    
    for indRun = 1
        Timing.RunInitiation = GetSecs();
        Timing.lastTiming = 'NaN';
        for indBlock = 1
            % initialize state cues of current condition
            if strcmp(setup.task, 'dynamic')
                StateSwitch_addSurroundingCues_dynamic(expInfo, screenInfo, 1, 1, 1);
            elseif strcmp(setup.task, 'words')
                StateSwitch_addSurroundingCues_words(expInfo, screenInfo, 1, 1, 1);
            elseif strcmp(setup.task, 'visual')
                StateSwitch_addSurroundingCues_visual(expInfo, screenInfo, 1, 1, 1);
            end
            oldTextSize = Screen('TextSize', screenInfo.curWindow, 30);
            DrawFormattedText(screenInfo.curWindow, ['relevante Attribute: ', num2str(expInfo.StateOrderRun{indRun}(indBlock,1))], 'center', 'center');
            Screen('TextSize', screenInfo.curWindow, oldTextSize); clear oldTextSize;

            % ####### Block cue onset #####
            if strcmp(expInfo.timing, 'absolute') || strcmp(expInfo.timing, 'relativeITI')
                flipWhen = Timing.RunInitiation+(indBlock-1)*expInfo.durBlockOnset+(indBlock-1)*expInfo.blockLengthDim*expInfo.trialDuration.all+(indBlock-1)*expInfo.durReward-(ifi/2);
            elseif strcmp(expInfo.timing, 'relative')
                if strcmp(Timing.lastTiming, 'NaN')
                    flipWhen = 0;
                elseif strcmp(Timing.lastTiming, 'ITI')
                    flipWhen = Timing.ITIOnset+expInfo.durITI-(ifi/2);
                end                
            end
            Timing.BlockInitiation = Screen('Flip', screenInfo.curWindow, flipWhen);
            Timing.lastTiming = 'BlockCue';
            ExperimentProtocol = [ExperimentProtocol; {'BlockInitiation'}, {Timing.BlockInitiation}, {[]}, {[]}, {[]}, {indRun}, {indBlock}, {[]}, {[]}];
            for indTrial = 1:setup.pr.ntrials_conj
                Timing.TrialInitiation = GetSecs();
                ExperimentProtocol = [ExperimentProtocol; {'TrialInitiation'}, {Timing.TrialInitiation}, {[]}, {[]}, {[]}, {indRun}, {indBlock}, {[]}, {[]}];
                if strcmp(setup.task, 'dynamic')
                    % create fixation
                    targets = makeDotTargets(screenInfo, expInfo); % initialize targets
                    %showTargets(screenInfo, targets, 1);
                    [~, expInfo, ExperimentProtocol,ResultMat,DisplayInfo,Timing] = ...
                    StateSwitch_trialPresentation_dynamic_170829(screenInfo, expInfo, targets, indRun, indBlock, indTrial, ...
                    ExperimentProtocol,ResultMat,DisplayInfo,Timing,setup);
                elseif strcmp(setup.task, 'words') || strcmp(setup.task, 'visual')
                    [~, expInfo, ExperimentProtocol,ResultMat,DisplayInfo,Timing] = ...
                    StateSwitch_trialPresentation_words_visual_170829(screenInfo, expInfo, [], indRun, indBlock, indTrial, ...
                    ExperimentProtocol,ResultMat,DisplayInfo,Timing,setup);
                end
            end
        end
    end
    
    Results{1,5} = expInfo;
    Results{2,5} = ExperimentProtocol;
    Results{3,5} = ResultMat;
    Results{4,5} = DisplayInfo;
        
     %% save practice files
    
    save(sessionFile, 'Results', 'setup')
    
    pause(1);
    
    %% inform the subject that the experiment is over
    
    DrawFormattedText(screenInfo.curWindow, 'Sie haben das Training nun beendet! \n\n Falls Sie noch Fragen haben, wenden Sie sich bitte an die Versuchsleiter.', 'center', 'center', [255 255 255]);
    Screen('Flip', screenInfo.curWindow);
    
    %% automatically close screen after 5 s
    
    pause(5);
    
%     disp('Experimenter input required: close experiment');
% %     while true
% %       [exitKeyPressed, resumeKeyPressed] = checkKeys_byKeyB(expInfo, screenInfo.keyboard_exp);
% %       if exitKeyPressed || resumeKeyPressed
% %         break
% %       end
% %     end

  catch exception
    getReport(exception) % show stack trace
  end

  closeExperiment; % close drawing canvas
  Screen('Preference', 'Verbosity', oldVerbosityLevel); % restore verbosity

end