Website Overview
What is the relation of this website to the book?
The main purpose of this website is to let you copy the code presented in the text onto your own computer. There, you can run it yourself, to see outputs from the code in color, motion, and/or sound, and to study solutions to some of the problems at the ends of the book's chapters. The full explanation of the code and supplementary material is provided in the book. This website is meant as a supplement to the book rather than a replacement for it.
How do I use the Code and Output resources on my own computer?
The Code and Output files are functionally identical to the code and output that you will find in the text. You may find you would like to run a program that is described in the text. The code can be copied directly from the browser to either your Command window (where it will execute immediately on being pasted) or the Editor window (where you can use it to make your own .m script or function).
Why are some of the Code resources slightly different from those in the text?
In preparing the final text for publication, it was occasionally necessary to modify one or more lines of MATLAB code so they would fit within the margins of the page. The code on the web site should still function the same as the code in the text.
Why do I get an error message when I run a code sample from the web site?
If a given code segment fails to run after it is copied from your web browser and pasted into the MATLAB Command or Editor Window, consider these possible causes:
1. If the failure is an "undefined variable", that variable may be defined in a code sample from earlier in the chapter that you have not yet run, or your code sample may otherwise be dependent on prior code that needs to run first to set the values of particular variables. In such a case, look back at the immediately preceding code samples to see if an earlier code sample has to be run before the one that is giving you trouble. Not every code sample is intended to run completely on its own.
2. If you have copied a code sample from the web site and pasted it directly into the MATLAB editor, look to see if the single-spaced code sample from the web page has been converted to double-spaced in the MATLAB editor or command window. Most code will run fine whether single or double spaced, but there is an important exception: When the code uses the three-dot operator to indicate the continuation of a line, the continuation must be on the very next line of code. If there is a blank line after the continuation, there's an easy fix: you can delete the blank line, restoring the continuation line to just after the line ending with the continuation operator, and all should be well.
3. Code that has continuation lines may still fail on occasion if it has been copied and pasted from another program, and it contains any code that continues onto the next line using the three-dot continuation operator (...). That is because many programs by default "auto-correct" the spelling of three period characters in a row (...) by deleting them and substituting the printer's single ellipsis character (…), which is not a legal character in MATLAB. The solution is simple: In the MATLAB editor, find each ellipsis character and replace it with the three-dot continuation operator.
How should I use the Solutions resources?
The solutions to selected problems in the text are provided for each of the chapters (except for Chapters 1 and 15, which do not include problem sets).
While solutions to many problems are available to you, you are strongly urged to look at them only after you have already done your level best to solve them on your own. It may be tempting to take a peek before you start, but doing so will greatly diminish your own motivation to solve the problems yourself. There is a great volume of research (as well as the authors' practical experience) which suggests that learning how to program can only occur through practice in solving programming problems. Simply reading the solutions will not do you much good! Use them only to check your own work, and to see possible alternative solutions.
You can profit from the solutions in two ways. First, you can simply read the Solutions file in your browser to view the solutions and the commentary on them. Second, you can copy all or part of the code from the browser window and execute the code by pasting it into your Command Window or the Editor. In the Editor, you can modify the code to understand it better and to adapt it to your own needs.
For Chapters 6, 11, and 12 there are some additional files that you can download that cannot be demonstrated in the browser.
For Chapter 13, in which the examples generate graphics and animation using Psychtoolbox, the code for each of the solutions is also provided as a stand-alone function (.m file), to make it easier for you to run and modify them yourself. The solutions for problems 1-4, 6-8, 10, and 11 have each been archived as a separate file, along with two other needed files (a sound file, error.wav, and an image file, lab_photo.jpg). All of these can be downloaded together in the compressed file PsychtoolboxSolutionsFiles.zip. The solutions to problems 5 and 9 are left to you.
How were the Solutions files for this website generated?
The Solutions files were generated using the Publish feature of MATLAB. Publish automatically makes a web-compatible .html file from a program source .m file using formatting that makes your program example almost self-documenting. More about Publish can be found in the MATLAB online help.