purpose: initializes the screen
usage: myscreen = initScreen(<myscreen>,<randstate>)
| argument | value |
| myscreen | Contains any desired initial parameters, can be left off if you are just using all defaults |
| randstate | Sets the initial status of the random number generator. This can either be an integer value, or it can be the field myscreen.randstate to set the state back to what it was on a particular experiment. |
This function initializes the screen by calling mglOpen, and also handles a number of different default initialization procedures such as setting up the gamma table with the correct linearization table. You should call this once at the beginning of the experiment. The variable myscreen will contain many fields associated with the status of the screen and records events like volume acquisitions and trial/segment times etc.
purpose: initializes the global stimulus variable name
usage: myscreen = initScreen('stimulusName',myscreen);
| argument | value |
| stimulusName | string that contains the name of the global variable that is used for your stimulus (i.e. if you had global stimulus, then this should be 'stimulus') |
| myscreen | myscreen variable returned by initScreen |
Note that this function, only needs to be called if you want to save the stimulus in your stim file. Since stimulus is a global variable, if you call this function, at the end of the experiment it will get the global variable with the name you specified here and save it in your stim file. If you do not need to save your stimulus variable, you do not need to call this function.
purpose: initializes a task variable
usage: [task myscreen] = initTask(task,myscreen,startSegmentCallback,screenUpdateCallback, trialResponseCallback, <startTrialCallback>, <endTrialCallback>, <startBlockCallback>)
| argument | value |
| task | Parameters for the particular task (note this must be a struct not a cell array, for a cell array, call initTask fore each element of the cell array. |
| myscreen | Variable returned by initScreen |
| startSegmentCallback | Function pointer that will be called at start of a segment |
| screenUpdateCallback | Function pointer that will be called every screen update (i.e. for a 60Hz buffer once every 1/60 of a second) |
| trialResponseCallback | Function pointer that will be called when the subject responds and getResponse is set |
| startTrialCallback | Function pointer that will be called at start of a trial |
| endTrialCallback | Function pointer that will be called at end of a trial |
| startBlockCallback | Function pointer that will be called at start of a block |
The task variable gets set up as explained above. Here is a list of valid fields:
| field | value |
| verbose | display verbose message when running tasks (probably shouldn't be set for real experiment since print statements can be slow) |
| parameter | task parameters |
| seglen | array of length of segments (used when not using segmin and segmax) |
| segmin | array of minimum length of segment |
| segmax | array of maximum length of segment |
| segquant | array of quantization of segment lengths (used with segmin and segmax–i.e. if you want segments to be randomized in steps of 0.6 seconds, then set the sequant for that segment to be 0.6) |
| synchToVol | array where one means that the segment will synch to the next volume acquisiton once the segment is finished. |
| getResponse | array where one means to get subject responses during that segment, set to zero means that subject responses will be ignored and the responseCallback will not be called |
| numBlocks | number of blocks of trials to run before stopping |
| numTrials | number of trials to run before stopping |
| waitForBacktick | wait for a backtick before starting task phase |
| random | randomize the order of parameters for each trial when set to 1, otherwise have the parameters go in order |
| timeInTicks | when set to 1, segment legnths are in screen updates (not in seconds) |
| timeInVols | when set to 1, segment lengths are in volumes (not in seconds) |
| segmentTrace | internal variable that controls what trace this task will use to save out segment times (usually you will not set this) |
| responseTrace | internal variable that controls what trace this task will use to save out subject responses (usually you will not set this) |
| phaseTrace | internal variable that controls what trace this task will use to save out the phase number (usually you will not set this) |
| parameterCode | For parameters that have groups |
| private | A parameter that you can do whatever you want with |
| randVars | random variables |
| fudgeLastVolume | When you synchToVol or keep time in volumes, and want to have the experiment run for a set number of trials, the experiment won't usually end because in the last segment it is waiting for a volume to come in that never will. If you set this to 1, it will fudge that last one so that the experiment ends one TR after the last volume is aquired. |
purpose: updates the task
usage: [task myscreen phaseNum] = updateTask(task,myscreen,phaseNum)
| argument | value |
| task | task variable, note task must be a cell array. If you only have one task phase, make phaseNum=1 and task a cell array of length one. |
| myscreen | myscreen variable returned by initScreen |
| phaseNum | The task phase you are currently updating. If you only have one phase, set to 1, for multiple phases, update Task will take care of switching from one phase to the next. |
purpose: updates the screen
usage: [myscreen task] = tickScreen(myscreen,task);
| argument | value |
| myscreen | myscreen variable returned by initScreen |
| task | task variable |
This function calls mglFlush to update the screen when it is needed and also checks for volumes and keys etc. Called with in main loop.
Implements a staircase for control of stimulus variable values. Type 'help upDownStaircase' for details. Also see taskTemplateFlashingStaircase.m and taskTemplateStaticStaircase.m for examples of using this function.
Allows you to force a move to the next segment or the next trial:
task = jumpSegment(task) % this will end the segment and move to the next one
task = jumpSegment(task,inf) % this will end the trial and start a new trial