A copy is also included in PsychBench in <PsychBench folder>/demos, so you can run it from there.
<cdcm>% SCANNER, SYNC IN EACH TRIAL DEMO<cdcm>
<cdcm>% Coding method<cdcm>
<cdcm>% --------------------------------------------------<cdcm>
<cdcm>% Each trial shows one of three pictures and the subject responds with any key<cdcm>
<cdcm>% press. Picture onset is 0.75 sec after sync trigger from a scanner in each<cdcm>
<cdcm>% trial. The picture shows until the subject responds or for 2 sec, whichever<cdcm>
<cdcm>% occurs first. We run 4 repetitions of each of the 3 picture trials for a total<cdcm>
<cdcm>% of 12 trials, all in random order.<cdcm>
<cdcm>%<cdcm>
<cdcm>% This scanner demo syncs in each trial and element timing is relative to sync.<cdcm>
<cdcm>% See also scannerSyncInBlocksDemo.m.<cdcm>
<cdcm>% Mark start of experiment script<cdcm>
newExperiment
<cdcm>% 3 trial definitions: 3 pictures<cdcm>
fileNames = [<cdsm>"sphere.png"<cdsm> <cdsm>"cube.png"<cdsm> <cdsm>"hourglass.png"<cdsm>];
<cdkm>for<cdkm> f = 1:3
<cdcm>% Simulate trigger by key press for this tutorial.<cdcm>
<cdcm>% Many scanners send triggers as key presses, in which case would use a keyPress object in a real experiment too.<cdcm>
<cdcm>% By default listens for any key (could be changed in property .listenKeyNames).<cdcm>
syncer = keyPressObject;
<cdcm>% Listen for key press from default keyboard just for this demo.<cdcm>
<cdcm>% In a real experiment would need to set this to point to whatever device the trigger is coming from.<cdcm>
syncer.n_device = [];
<cdcm>% Register input as a trigger instead of response from subject<cdcm>
syncer.registerTrigger = true;
<cdcm>% Sync experiment at trigger so can set elements to start/end at times from sync<cdcm>
syncer.syncExperiment = true;
<cdcm>% Default start at trial start.<cdcm>
<cdcm>% By default keyPress elements end when they record a trigger/response -> don't need to set .end.<cdcm>
<cdcm>% Report sync time ( = trigger time)<cdcm>
syncer.report = <cdsm>"syncTime"<cdsm>;
<cdcm>% Picture stimulus.<cdcm>
<cdcm>% Start at time from sync = 0.75 sec.<cdcm>
<cdcm>% End at response or time from sync = 2.75 sec (2 sec duration), whichever occurs first.<cdcm>
pic = pictureObject;
pic.fileName = fileNames(f);
pic.height = 8;
pic.start.t_sync = 0.75;
pic.end(1).response = true;
pic.end(2).t_sync = 2.75;
pic.report = [<cdsm>"fileName"<cdsm> <cdsm>"startTime"<cdsm>];
<cdcm>% Response handler - any key press, this time for response from subject.<cdcm>
<cdcm>% Start at time from sync = 0.75 sec.<cdcm>
<cdcm>% By default ends on its own at response.<cdcm>
<cdcm>% Also end at time from sync = 2.75 sec if that occurs first.<cdcm>
recorder = keyPressObject;
recorder.start.t_sync = 0.75;
recorder.end.t_sync = 2.75;
recorder.report = <cdsm>"responseTime"<cdsm>;
<cdcm>% Note make sure each trial starts soon enough to allow it to receive its trigger.<cdcm>
<cdcm>% e.g. here minimum time between triggers = 0.75 + 2 + pre-trial interval sec.<cdcm>
<cdcm>% Default pre-trial interval = 0.75 sec, or can change in trial object property .preTrialInterval.<cdcm>
<cdcm>% Add trial definition with default numbering (1, 2, 3, ...)<cdcm>
addTrial(syncer, pic, recorder);
<cdkm>end<cdkm>
<cdcm>% Trial list: run 4 of each trial definition in random order<cdcm>
nn = randomOrder(rep(1:3, 4));
setTrialList(nn)
<cdcm>% Run<cdcm>
[results, resultsMatrix] = runExperiment;
<cdcm>% See also:<cdcm>
<cdcm>% - element types cedrusPress, responsepixxPress, etc. for button boxes<cdcm>
<cdcm>% - pb_prefs() -> screen tab -> flip horizontal/vertical (screen object<cdcm>
<cdcm>% properties .flipHorz/flipVert) for display through a mirror<cdcm>