MOLE
Modifiable Language Experiments
Modifiable Language Experiments
Our lab relies heavily on experimental procedures coded in MATLAB. For those interested, we have created a database that provides several of the most-used functions from our lab, along with read-me’s, code comments, and demos so that others may utilize this code for their own experiments.
This material is based upon work supported by the National Science Foundation under Grant Number 123-0003. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the Professor Creel and her lab, and do not necessarily reflect the views of the National Science Foundation.
As many developmental researchers know, it is simple to ask an adult to perform hundreds of repetitive trials in front of a computer screen, but it is no easy task to ask children to do the same thing (while still obtaining reliable data). As a result, our experiments are made more engaging for a younger audience (e.g. cartoon characters perform actions on the screen while a voice identifies the character). Because we also collect eyetracking data on our preschool subjects, these experiments must be coded in MATLAB for precise timing data. The goal of this page is to make our commonly-used MATLAB functions available to other researchers, so that they may build off of what we have already created for their own experimental procedures.
On this website, you will find several things of use to you, described below.
Read Me’s: Below this post are several other posts that function as read-me’s for the eight functions on this website. Each read-me walks you through how the function works by detailing the input arguments and by providing examples. If you would like to download a copy to your computer, there are links at the bottom of each post where you may do this.
Demo Walkthroughs: On the bottom of this page, you will Demo Walkthroughs. This section has step-by-step instructions that will guide you through downloading and using these functions on your own computer. It will provide you with a complete list of the files that you will need to run each function’s demo, and will generally serve as a troubleshooting guide for running the demos.
Demo Materials: Below the Demo Walthroughs are the Demo Materials. This is where you can download the zip file containing all of the materials for the demos (basic functions with internal comments, text files, stimuli, etc).
PsychoPy
August 12, 2014 11:32 am ⋅ Sarah Creel
I had some trouble getting Matlab PTB3 to allow users to fluently type sentences for transcription. I found a function to do it in PsychoPy (http://www.psychopy.org/wiki/home.php/Snippets/LiveUpdatingText), and I modified it to allow capital letters and a few symbols. Download this here: PsychoPyTyping
runTranscribe.py
Run this by clicking the green running-man figure in the PsychoPy toolbar. It will prompt you to fill in subject information and to transcribe three words. (Make sure to leave the list name “shortlist” intact!)
Try typing some full sentences.
getTyping.py
This is the function that actually takes in keystrokes and displays them on the screen. It supports a single backspace at a time, but doesn’t do
qaires.py
This collection of functions allows you to prompt participants to provide potentially relevant information. However, there’s currently nothing to stop them from just hitting Enter or clicking OK without filling anything out.
Read-Me's
October 17, 2012 2:25 pm ⋅ Annie Ditta
Description
This function takes as input a cell array specifying a block of trials (includes drawing the test stimuli to the screen, playing the audio files, etc.) and allows the user to connect the eyetracker, specify trial order, and specify the type of feedback to be given to subjects.
General
This function takes a specified list of trials (pictures to be shown to and sounds to be played for the subject) and runs through them in a specified order.
trialList and windowPtr must be specified so that the function knows which trial list to display on which screen.
The optional arguments ET, order, feedback, folder, and pictureCoords can be altered depending on the needs of the experiment.
ET turns the eyetracker on,
order specifies whether the trials are presented sequentially or randomly,
feedback specifies which type of feedback to give the subjects (no feedback for artificial lexicon testing, feedback for artificial lexicon learning, and click until correct most likely for real words),
folder specifies where to access the stimuli if they are in a different folder from the one being worked out of, and
pictureCoords allows the experimenter to place the image stimuli in any coordinates desired.
This function will return percent correct (correctness) from the trials to the main program so that the value can be easily used to evaluate performance.
Usage
[correctness] = runTrialBlock(trialList,windowPtr,ET,order,feedback,folder,pictureCoords)
Ex. runTrialBlock(‘ExpATrials’,5,ETstruct,’RANDOM’,’FEEDBACK’,’ExpA/’,[10 20 30 50; 50 20 70 50; 10 40 30 70; 50 40 70 70]);
OR (this is the same function as the one listed above, only using the defined variable names listed below in the Arguments section):
Ex. runTrialBlock(arg1,arg2,arg3,arg4,arg5,arg6,arg7)
Arguments
trialList: String value. The name of the list of trials to be loaded.
Ex. arg1 = ‘ExpATrials’
windowPtr: Numerical value specifying the window for the stimuli to be printed to.
Ex. arg2 = 5
ET: Optionally skip connecting the eyetracker via the numerical input 0. Currently, there is no default for connecting the eyetracker. Either the shell code specifies a variable containing the eyetracker struct, or the user must specify 0 for no eyetracking.
Ex. arg3 = ETstruct
order: Optional string value that can specify the trial order to be random via the command ‘RANDOM’. Will default to ‘SEQUENTIAL’. Inputs are case sensitive, and must be in all caps.
Ex. arg4 = ‘RANDOM’
feedback: Optional string value that lets the user specify the type of feedback desired. Can choose between ‘NOFEEDBACK’, ‘FEEDBACK’, or ‘CLICKTILLRIGHT’. Will default to delivering no feedback. Inputs are case sensitive, and must be in all caps.
Ex. arg5 = ‘FEEDBACK’
folder: String value. Optionally specify the name of the folder containing the stimuli, with a forward slash ( / ) after the name. It will default to the current folder being worked out of.
Ex. arg6 = ‘ExpA/’
pictureCoords: Optional numerical values that allow picture coordinates to be specified. Each vector will consist of 4 numbers that denote the locations of the upper left and lower right corners (x,y coordinates) of the image. Can specify the coordinates of multiple pictures by creating new rows for each set of coordinates (maximum number of pictures on screen at a time is 4).
Ex. arg7 = [10 20 30 50; 50 20 70 50; 10 40 30 70; 50 40 70 70]
Notes
All arguments that require string values must be entered surrounded by single quotation marks (‘ ‘).
All inputs are case sensitive.
The (x,y) coordinate system in MATLAB is different from the normal coordinate system. The (0,0) point is in the upper left corner, and infinity in both directions is in the lower right corner, so the y values must always be larger than the x values.
To specify new rows for the image vectors, use a semi-colon, not the return key.
All vectors must be surrounded by brackets ( [ ] ).
Download
October 17, 2012 2:17 pm ⋅ Annie Ditta
Description
This function is a frame function for inputdlg that prompts the subject to answer specified questions, and allows the user to store the subject’s answers with his/her experimental data.
General
This function adds onto the inputdlg function by allowing the information entered into the questionnaire to be appended to the subject’s data file. This function takes a text file containing question info, length of response lines, and default answers and loads it into a questionnaire format for subjects to enter responses.
See help inputdlg for more information.
Usage
runQuestions(instrfile,expt)
Ex. runQuestions(‘Questionnaire’,’ShapesExpQ’)
Arguments
instrfile: String input that specifies the name of the file containing the questions.
Ex. ‘Questionnaire’
expt: String input that specifies the name of the file to append the questionnaire data to. This should be a file that is named for the experiment that the questionnaire follows/asks about.
Ex. ‘ShapesExpQ’
Notes
All string inputs must be surrounded by single quotation marks ( ‘ ‘ ).
When specifying the length of the answer lines, make sure to include the length of the question as well, since if it is too short, the program will wrap your answer text to the next line.
Download
October 17, 2012 2:10 pm ⋅ Annie Ditta
Description
This function is a frame function for inputdlg that prompts the subject to answer specified questions, and allows the user to store the subject’s answers with his/her experimental data.
General
This function adds onto the inputdlg function by allowing the information entered into the questionnaire to be appended to the subject’s data file. This function takes a text file containing question info, length of response lines, and default answers and loads it into a questionnaire format for subjects to enter responses.
See help inputdlg for more information.
Usage
runNamingBlock(pictureList,windowPtr,order,folder,pictureCoords)
Ex. runNamingBlock(‘NameExpTrials’,5,’RANDOM’,’NameExp/’,[10 20 30 50]);
OR (this is the same function as the one listed above, only using the defined variable names listed below in the Arguments section):
Ex. runNamingBlock(arg1,arg2,arg3,arg4,arg5)
Arguments
pictureList: String value that specifies the text file with the list of image file names (NOT the pictures themselves).
Ex. arg1 = ‘NameExpTrials’
windowPtr: Numerical value that specifies which screen the stimuli are going to be drawn to.
Ex. arg2 = 5
order: Optional string value that allows the user to specify the order of trials to be random (‘RANDOM’). Defaults to sequential (‘SEQUENTIAL’).
Ex. arg3 = ‘RANDOM’
folder: Optional string value that specifies the folder where the stimuli are located. If this is not specified, it will default to the current folder being worked out of.
Ex. arg4 = ‘NameExp/’
pictureCoords: Numerical values in a 4 element vector that specify the coordinates for the image stimuli.
Ex. arg5 = [10 20 30 50]
Notes
All string input argument must be surrounded by single quotation marks ( ‘ ‘ ).
All string inputs are case sensitive.
All vectors must be surrounded by brackets ( [ ] ).
When specifying a folder to be worked out of, the name of the folder must be followed by a forward slash ( / ).
The (x,y) coordinate system in MATLAB is different from the normal coordinate system. The (0,0) point is in the upper left corner, and infinity in both directions is in the lower right corner, so the y values must always be larger than the x values.
Download
October 17, 2012 1:44 pm ⋅ Annie Ditta
Description
This function opens a specified file and formats it into an array of n rows by 14 (or more) columns that can easily be read by MATLAB.
General
This function will take the name of a file as an argument, and open the file into an array, labeled as “trialArray” in the format specified by the user. If no format is specified, the function will default to 1 column of numbers, and 13 columns of text.
trialArray is organized so that each column of the originally opened data file is its own array, which can be indexed via curly braces {}. To access a particular column of data, the user would enter trialArray{n}, where n specifies the number of the column desired. For example, the user would enter trialArray{1} to access the first column.
If a particular cell in the array is desired, an additional set of curly braces can be used to index a particular row in the specified column. For example, the user would enter trialArray{1}{4} to access the fourth row in the first column.
Usage
readTrialList(trialsfile, moreFormatting)
Ex. readTrialList(‘ExpATrials’,’%s%s%s’)
OR (this is the same function as the one listed above, only using the defined variable names listed below in the Arguments section)
Ex. readTrialList(arg1,arg2)
Arguments
trialsfile: The name of the file to be loaded.
Ex. arg1 = ‘ExpATrials’
moreFormatting: Optional character string denoting additional columns (e.g. ‘%s%s%s’ would be three additional columns of strings).
Ex. arg2 = ‘%s%s%s’
Notes
This function cannot be formatted to have fewer than 14 columns via the moreFormatting argument. If the user wants to format with fewer columns, the function itself would have to be altered (see program coding comments).
‘CommentStyle’,’%’ applies MATLAB’s default commenting system to the data file (e.g. “%This is a comment!” will not be read as part of the code when added to any information from this data file), but ONLY if the comment is added at the end of the set of columns. This will NOT work if the comment is inserted in the middle of the specified number of columns.
All string inputs are case sensitive.
Download
October 17, 2012 1:36 pm ⋅ Annie Ditta
Description
This function shuts down all of the extensions that have been opened during the course of the experiment.
General
This function will close the PsychToolbox screen (where the stimuli were presented), PsychPortAudio (used to play the audio stimuli), any files that were opened in the course of the experiment (trial lists, recorded data, etc), and will stop the eyetracker from recording and subsequently shut it down.
Usage
qqq
Arguments
There are no arguments that need to be fed to this function.
Notes
All programs should have these close functions built into them, but this function is a catch-all in case the experimenter is prone to forgetting to shut down some extensions.
Because the function is called qqq, it is important to remember not to use qqq as a variable name in the code!
Download
October 15, 2012 4:25 pm ⋅ Annie Ditta
Description
This function takes a text file of pre-written instructions and prints them to the screen so the subject can see them.
General
This function will take the specified text file (instrfile) and will print it to the specified screen/window (winPtr). The instructions themselves will be loaded into an array, and then lines of that array will be printed to the screen, but will not be shown to subjects until the screen is flipped.
You can specify a key to be pressed (or the mouse to be clicked) to move on after reading the instructions via the ‘key‘ argument. The current default for key press is space bar.
This function also allows for text display characteristics to be altered if the experimenter desires. The text height (size), text color, and background color of the screen can all be altered via the 3-element vector that specifies colors. The current defaults, respectively, are 20, pink, and white.
Usage
printInstructions(instrfile,winPtr,[key],[textHeight],[textColor],[bgColor])
Ex. printInstructions(‘ExpAInstructions’,5,’mouse’,50,[0 206 209],[240 128 128])
OR (this is the same function as the one listed above, only using the defined variable names listed below in the Arguments section):
Ex. printInstructions(arg1,arg2,arg3,arg4,arg5,arg6)
Arguments
instrfile: The name of the text file of instructions to be loaded.
Ex. arg1 = ‘ExpAInstructions’
winPtr: Numerical value designating which window the instructions are going to be printed to.
Ex. arg2 = 5
key: Specifies which key is to be pressed in order to advance from the instructions. The default is SPACE (the spacebar key). Can also be specified as ‘mouse‘ to advance with a mouse click, as opposed to a key press.
Ex. arg3 = ‘mouse’
Ex. arg3 = ‘a’
textHeight: Numerical value that designates the size of the text to be printed to the screen. If no value is entered, textHeight defaults to 20.
Ex. arg4 = 50
textColor: Numerical 3-element vector that designates the color of the instructions text to be printed to the screen. If no value is entered, textColor defaults to pink [255 0 255].
Ex. arg5 = [0 206 209]
Specifies the text color to be dark turquoise.
bgColor: Numerical 3-element vector that designates the color of the background screen for the instructions to be printed on. If no value is entered, bgColor defaults to white [255 255 255].
Ex. arg6 = [240 128 128]
Specifies the background color to be light coral.
Notes
This function works only with PsychToolbox installed.
This function will not wrap text; carriage returns must be present in instrfile.
All strings fed to the function must be entered surrounded by single quotation marks ( ‘ ‘ ).
Google can be used to find 3-element vector color codes (RGB codes) easily.
All string inputs are case sensitive.
All vectors must be surrounded by brackets ( [ ] ).
Download
October 15, 2012 3:54 pm ⋅ Annie Ditta
Description
This function moves a character through a specified set of actions on the screen while a sound file plays.
General
This function is used to create a scene stimulus in which a character is moved around the screen in a specified set of actions while a corresponding sound file plays (e.g. what the character is saying).
For this function, order, shape, wordsound, action, and window must all be specified.
order specifies whether to display the images in sequential or random order,
shape specifies the image for the character,
wordsound specifies the sound file to be played,
action specifies which movements the character will make, and
window specifies where to display the stimuli.
folder and background can be left blank, and the function will fill in default values for these arguments.
folder specifies where MATLAB should pull the stimuli from, and
background specifies an image for the background should the user desire one.
Usage
moveAndTalk(order,shape,wordsound,action,window,folder,background)
Ex. moveAndTalk(‘SEQUENTIAL’,norming{2},norming{3},norming{4},5,’CatExp/’,’NormingBG.jpg’)
OR (this is the same function as the one listed above, only using the defined variable names listed below in the Arguments section):
Ex. moveAndTalk(arg1,arg2,arg3,arg4,arg5,arg6,arg7)
Arguments
order: String value that specifies the order of actions to be displayed. Can choose from ‘RANDOM’ or ‘SEQUENTIAL’ (there is no default).
Ex. arg1 = ‘SEQUENTIAL’
shape: 1xn cell array of string values that specifies the .jpg image file of the character to be moved around the screen for each trial.
Ex. arg2 = norming{2}
wordsound: 1xn cell array of string values that specifies the .wav file to be played while the image is moved around the screen for each trial.
Ex. arg3 = norming{3}
action: 1xn cell array of string values that specifies the action for the character to do for each trial. Currently can choose from ‘vbounce’, ‘lefthop’, ‘righthop’ (all bouncing motions), ‘leftstroll’, ‘rightstroll’ (walk-in moves), ‘leftpeep’, ‘rightpeep’,(peeping from behind L or R tree), ‘uppeep’ (peeping up from beneath the grass, center of screen), and ‘distractor’, which is a non-test trial action.
Ex. arg4 = norming{4}
window: Numerical value that specifies the window that the stimuli should be drawn to (window pointer).
Ex. arg5 = wptr
folder: String value that specifies the folder containing the image and sound stimuli. If this is not specified, it defaults to the current folder being worked out of.
Ex. arg6 = ‘CatExp/’
background: String value that specifies the background of the scene. Currently defaults to 0 (no background), but if it is specified, will read the background from the folder specified in the folder argument.
Ex. arg7 = ‘CatBG.jpg’
Notes
The specifications for arguments 2, 3, and 4 (shape, wordsound, action) are all contained in separate columns in the text file that the shell script loads. Therefore, they are specified in the function by indexing the column within the cell array as shown with curly brackets ( {} ) above.
All arguments that are strings must be surrounded by single quotation marks ( ‘ ‘ ).
The shape argument should refer to a .jpg file that is 200×200 pixels in size, to avoid strange appearances.
The user could add their own hard code in the function (adding on to the large switch-case statement) to program for different actions.
All string inputs are case sensitive.
When specifying a folder to be worked out of, the name of the folder must be followed by a forward slash ( / ).
Download
October 15, 2012 2:34 pm ⋅ Annie Ditta
Description
This function adds on to the built-in MATLAB function wavread by converting the input sound file to the correct format (2 channel, stereo sound) instead of crashing the program.
General
This function will read in the sound file specified and will transform the direction of the vector if it is in a format that PsychPortAudio is unfamiliar with. This function also allows for the optional argument ‘side’ to be specified, which will play the sound to one specified ear (one side of the headphones).
If the optional argument is specified, the function is able to format a stereo sound to act as a mono sound by overwriting one sound channel with no sound.
The function will return your correctly formatted sound, along with the sampling rate of the sound.
Usage
fancywavread(soundfile,side)
Ex. fancywavread(‘ExpASound’)
Ex. fancywavread(‘ExpASound’,’L’)
Arguments
soundfile: String input that specifies the name of the sound file (.wav format) to be played.
Ex. ‘ExpASound’
side: Optional string input that specifies which ear the mono sound should be played to. Input takes the form of either ‘L’ for left, or ‘R’ for right.
Ex. ‘L’
Notes
All string inputs must be surrounded by single quotation marks ( ‘ ‘ ).
All string inputs are case sensitive.
If you feed this function a stereo sound but then specify the ‘side’ argument, the non-specified channel will be overwritten with blanksound to create a mono sound. This means you do not have to feed this function a mono sound if you want it to only be played to one side of the head.
Download
October 15, 2012 2:34 pm ⋅ Annie Ditta
Description
This function adds on to the built-in MATLAB function wavread by converting the input sound file to the correct format (2 channel, stereo sound) instead of crashing the program.
General
This function will read in the sound file specified and will transform the direction of the vector if it is in a format that PsychPortAudio is unfamiliar with. This function also allows for the optional argument ‘side’ to be specified, which will play the sound to one specified ear (one side of the headphones).
If the optional argument is specified, the function is able to format a stereo sound to act as a mono sound by overwriting one sound channel with no sound.
The function will return your correctly formatted sound, along with the sampling rate of the sound.
Usage
fancywavread(soundfile,side)
Ex. fancywavread(‘ExpASound’)
Ex. fancywavread(‘ExpASound’,’L’)
Arguments
soundfile: String input that specifies the name of the sound file (.wav format) to be played.
Ex. ‘ExpASound’
side: Optional string input that specifies which ear the mono sound should be played to. Input takes the form of either ‘L’ for left, or ‘R’ for right.
Ex. ‘L’
Notes
All string inputs must be surrounded by single quotation marks ( ‘ ‘ ).
All string inputs are case sensitive.
If you feed this function a stereo sound but then specify the ‘side’ argument, the non-specified channel will be overwritten with blanksound to create a mono sound. This means you do not have to feed this function a mono sound if you want it to only be played to one side of the head.
Download
Demo Walkthroughs
Here you will find all the information you need in order to download and run one or more of our demos. To get started, you should have…
MATLAB with PsychToolbox installed on your computer
The Demo Materials folder, unzipped
Should contain the basic function codes with comments, demo functions, text files, & audiovisual stimuli
Step by Step
To download the materials you will need for the demos, go to the “Demo Materials” page on the top navigation bar under this page’s tab. There should only be 1 zipped file there. Click on it (or right click and save as) to download it. Save it to the desktop. Now, go to the folder and unzip it with the specified program (should already be on your computer). Make sure you unzip the file to a location you will remember, as you will need to navigate to it in MATLAB in order to run the demos. This folder should contain everything you need, but check to make sure it has the basic functions with comments (8 of them), demo function scripts, text files, and audiovisual stimuli.
You should already have MATLAB with the latest version of PsychToolbox installed. If this is not the case, please purchase a copy of MATLAB here: http://www.mathworks.com/store/default.do, and/or download the free PsychToolbox add-on here: http://psychtoolbox.org/PsychtoolboxDownload.
If you already have copies of both of these, it may be of use to you to know which version you are running. To find this out in MATLAB, open the program and at the command window prompt type “version“. To find this out in PsychToolbox, at the command window prompt type “PsychtoolboxVersion“.
Once you have MATLAB open on your computer, you will need to make sure that MATLAB is looking in the correct directory to run these demos. To do this, go to the top bar labeled “Current Directory.” If you know where the file is, you can type in the location, but the simpler way to specify this is to click the “…” button to the right of the directory bar. This will open a menu where you can navigate to the location that you unzipped the Demo Materials file to. Once you have found that folder, click on it and press “OK” to select it as your directory. It is important not to click anything inside the folder, as you don’t want to specify a subfolder as your directory – it won’t have all the components in it!
You should now be ready to run one of the demos. All you have to do at this point is type the name of the demo at the command prompt (case-sensitive). The demos will be the only files with the extension .m that have the word “Demo” in them, so they should be easy to locate within the Demo Materials folder (Mac users should find these files color-coded green or yellow). If you want to understand how the demos work, you should open the basic functions (.m files without the word “Demo”) and read the internal line-by-line code comments (comments should be green when opened in MATLAB).
Good luck!
Specific Notes
runShapesDemoFull & runTrialBlock
This demo demonstrates the data file saving abilities of the full runTrialBlock function. In the Demo Materials folder, there should be an empty folder called savedData. This is where the data files will go once the demo is over. If you do not have this folder, the saving function will not work!
This applies to runNamingBlock & moveAndTalk also. If you want to activate the save data file abilities for these functions, uncomment the lines that say “commented out for demo.” These should be lines with fid, fopen, fprintf, and fclose.
runNamingBlock & runNamingBlockDemo
This code is set up so that the list of names of the picture files (.txt file) must be in the same folder as the picture stimuli (.jpgs). In the Demo Materials folder, that is why there is a .txt file in the Stimuli/shapes/ folder.
General Notes
For all codes that require text files, these can be in one of two formats:
.txt files – if you choose this format, all file names must be completely spelled out with the file name extension in the MATLAB code (e.g. ‘TextFile.txt’)
Unix executable files – these files have no specific file extension in the MATLAB code (e.g. ‘TextFile’)
MATLAB switched the syntax for setting the random seed in version 2011a (7.12). All codes should take your MATLAB version into account and utilize the correct shuffle function.
Demo Materials
Below is the link to download all of the materials you will need for running the demos. Please see the Demo Walkthroughs page for more details.
Right-click the link below and select ‘Save As’:
DemoMaterials
Help
If you run into any problems that are not addressed on the website, you are welcome to email Dr. Sarah Creel, the Principal Investigator of the LASR Lab. When you send an email, please title your subject line “MOLE,” so it is answered promptly.
Please only email if you have searched every corner of the website for a solution and you are absolutely certain there isn’t one!
Contact Information
Sarah C. Creel
[herlastname] at cogsci.ucsd.edu