MATLAB book
MATLAB for Psychologists (scripts and listings from the book)
Mauro Borgo, Alessandro Soranzo & Massimo Grassi
This page contains most of the scripts and functions included in the book as well as other types of additional materials. To save the scripts and the function right-click on the link and "save as". In alternative, open the link, copy and paste the content into the MATLAB editor. Note that the scripts and functions here presented are (when necessary) bug-fixed versions of the scripts reported in the book.
Chapter 2
Chapter 3
Chapter 4
- Listing 4.1
- Listing 4.2
- Listing 4.3
- Listing 4.4
- Listing 4.5
- Listing 4.6
- Listing 4.7
- Listing 4.8
- Listing 4.9
- Listing 4.10
- Listing 4.11
- Listing 4.12
- Listing 4.13
- Listing 4.14
- Listing 4.15
- Listing 4.16
- Listing 4.17
Chapter 5
- Listing 5.1
- Listing 5.2
- Listing 5.3
- Listing 5.4
- Listing 5.5, 5.6, 5.7
- Listing 5.8
- Pulsation threshold
- Darwin & Ciocca (onset synchrony/asynchrony)
- Listing 5.9
- Listing 5.10
- Listing 5.11
- Listing 5.12 (array if ITD sounds)
- Create envelope and generate Figure 5.2
- Listing 5.13
- Listing 5.14
Chapter 6
Chapter 7
- Listing 7.1
- Listing 7.2
- Listing 7.3
- Listing 7.4
- Listing 7.5
- Listing 7.6
- Listing 7.7
- Listing 7.8
- Listing 7.9
- Listing 7.10
- Listing 7.11
- Listing 7.12
- Listing 7.13
Chapter 8
Chapter 9
- Listing 9.1
- Listing 9.2
- Listing 9.3
- Listing 9.4
- Listing 9.5
- Listing 9.6
- Listing 9.7
- Listing 9.8
- Listing 9.9
- Listing 9.10
- Listing 9.11
Chapter 10
- Listing 10.1
- Listing 10.2
- Listing 10.3
- Listing 10.4
- Listing 10.5
- Listing 10.6
- Listing 10.7
- Listing 10.8
- Listing 10.9
- Listing 10.10
- Listing 10.11
- Listing 10.12
- Listing 10.13
- Listing 10.14
- Listing 10.15
- Listing 10.16
- Listing 10.17
- Listing 10.18
Brick scripts & functions
- The function that generates the event table that drives the brick experiment (listing 4.19)
- GenerateSound.m function (listing 5.15)
- Script for reading the data.txt file and prepare the data for the successive ANOVA (listing 7.14)
- The MATLAB figure for the graphical interface
- The script that drives the behavior of the graphical interface
- The script that draws the video stimulus of the brick
- SexulerExp.m function: the main function of the brick's experiment (listing 10.19)
To run the brick experiment: type "RunExp" at the prompt, fill-in the details, and either press "RUN PRACTICE" or "RUN EXPERIMENT" (see text for further details). During the experiment press either "b" (for bouncing) or "s" (for streaming) up to the experiment's end (it is currently set to run 40 trials).
Optimized brick functions:
Complex scripts and functions such as those written for the brick experiment requires several rows of code. The length of these codes is excessively long to be written (and read) in a book. For this reason, here we provide an alternative, optimized, more complete (and much longer) SekulerExp.m function. Differently from to the SekulerExp.m above, the following saves the data into a formatted text data file (similar to data.txt). Note that the writing is done "in append": if a datafile exists the new data are written in append to previous data. Moreover, the function has a different behavior whether you click "run practice" or "run experiment": only if you click "run experiment" the it writes the datafile. In addition, the new function interrogates the operative system and run the stimulus at maximal priority.
To use the optimized function you need to edit the RunExp.m function and replace "SekulerExp(handles);" with "SekulerExp2(handles);" (there are two substitutions to do).
Additional materials: