Common SPM Error Messages
This page collects the most common error messages found in SPM, and suggests some typical ways to troubleshoot or fix the error. Feel free to add your own!
Error Message: "Error reading information on <image file name>. Please check that it is the correct format."
Error Message: "Can't get volume information for <image file name>."
Situation: These two errors often occur together, and sometimes even pop up a warning box with the first message. The errors come from spm_vol, the function that maps .img files to Matlab's workspace. spm_vol is called in a variety of situations - beginning to estimate a model, beginning any spatial preprocessing step, or beginning any of the ArtifactDetection tools in the GablabToolbox. Any time you've got images being read, basically, you could get this error.
Cause: This is a generic error message that crops up if there's any trouble finding or reading an image file name. It can occur because the named file doesn't exist or isn't in the specified location. It can occur if the .img file is present, but the .hdr file is not, or vice versa. Or if there is some corruption in the .img file, or it's not a standard Analyze-format image, you'll get this as well.
Common Fixes: 90% of the time this error message comes up, it's because the image file it's looking for isn't in the right place. The very, very first thing to do is look in the specified directory and make sure both the .hdr and the .img files you've specified are in there. But what if you don't know where SPM is looking for them? The easiest way to find out is to turn on the Matlab debugger with dbstop if error and then run the exact steps that caused the error again. (See MatlabDebugging for more info on the debugger.) When the program stops again, your Matlab prompt will look like this: K>> At that prompt, type P(i,:). This asks Matlab to print the filename that spm_vol had the error with (stored in a matrix called P). When Matlab prints the filename, inspect it and make sure it lines up with where you think the images should be. You should use cd to try to go to that named directory to make sure it exists - oftentimes there will be a typo in the directory name. If there is no directory name listed, only a filename, Matlab is looking for them in the present working directory, so check there. If the directory exists, use dir to list the files in there and make sure both the .hdr and .img file are in there.
If it turns out the image files aren't in the right place, you need to adjust where SPM looks for them; this might mean fixing a typo in a script file, or something more complicated. A common source of this problem is moving or renaming or compressing the image files after you've specified the design, and then trying to estimate the model or run a script that calls the design file. In this case, you have two options: 1) move the files back to where they're supposed to be (or uncompress or rename them), 2) use the modifySPM script or a variant to change the design file to point in the right place. See GablabScripts for more info on those functions.
If you're really sure both the .hdr and .img files are in the exact directory they're supposed to be, then try looking at the file in question with SPM's "Display" button - see if it will load. If not, the file may be corrupted and you may have to re-create it or replace it with a backed-up version.
Error Message: "Cant open image file."
Situation: A variant of the error above, except this is called by spm_sample_vol, the function SPM uses to get values from individual voxels in an image, rather than read the whole image. Can be called in all the same situations - estimating a model, using a GablabToolbox function, preprocessing, etc.
Cause: Same reasons as above - some problem in opening a filename.
Common Fixes: Again, 90% or more of the time, this error is due to an image file not being in the right place. With spm_sample_vol, though, it can be trickier to figure out where the problem filename points, because just running the debugger won't put you into spm_sample_vol directly. (It's a compiled C function, so it can't be accessed by the debugger.) Run the debugger, and then when you have the K>> prompt, take a look at the error message. It should print the line the error came from: something like "On line 252 ==> Y(j) = spm_sample_vol(VY(j), X, Y, Z, 1)". The first argument to spm_sample_vol is a structure that has the filename of the desired image in it. So if you take the name of that variable - in this case VY(j) and add .fname to it, you'll get Matlab to print the filename. In this case, at the K>> prompt, you'd type VY(j).fname to get the filename that's giving you trouble. Then follow the steps above - use cd and dir to try and find the image file, and do what you need to do to get it in the right place or change the design file that points to it.
Error Message: "Error while evaluating uicontrol Callback."
Situation: Almost anytime, anywhere - anytime you're using a graphical interface.
Cause: This is a totally generic error message in Matlab that crops up whenever anything goes wrong in a function you've called from a graphical interface. By itself, it doesn't mean anything and doesn't give you any information about what went wrong. Any element in a graphical interface you can push is called a uicontrol in Matlab, and any function called from a uicontrol is called a callback - so all this says is you have some error in a function that was just called from the interface.
Common Fixes: Almost always, you can force Matlab to give you more information. If you find the button that you clicked on to call the function that crashed, and close the window that button is in (i.e., the SPM results interface, the SPM control window, the GablabToolbox, etc.), you can often get a more detailed error message out of Matlab. In the non-graphical Matlab interface, sometimes simply hitting return a few times will do the trick. Finally, if you turn on the Matlab debugger with dbstop if error and re-run the steps that caused the error, the error message during the debugger should be much more comprehensive. See MatlabDebugging for more on reading error messages and the debugger.
Error Message: "Index exceeds matrix dimensions."
Situation: Almost any situation during SPM, but most common during a batch script or other user-programmed interaction.
Cause: This is a pretty generic error in Matlab that simply indicates you tried to reference an element of a vector that doesn't exist. If A is a vector with five elements, and you try to say B = A(6), for example, you'll get this error.
Common Fixes: Fixing this error generally involves using the Matlab debugger, so see MatlabDebugging for a little primer if you're unfamiliar with it. Launch the graphical version of Matlab, start the debugger with dbstop if error and re-run the steps that caused the error. When it happens, read the line of the function that caused the error (the text window that pops up should have it highlighted with a green arrow). See if you can figure out what matrix is being referenced and what the index is. Use whos to figure out how big the local matrices are. Oftentimes the help text at the top of the function or the SPM Programmer's Cheat Sheet (see GablabScripts) can be helpful in understanding what the various named variables refer to. Find out the value of the index - often named i or j - and see if it's too big, then look back a few lines in the code and see if you can understand what i or j might be set to. Common reasons you might get this might include: your batch script has nsess equal to one number, but the number of images you specified with nscans or selecting your images doesn't line up; your number of subjects doesn't line up with your number of images in a large batch script; your number of conditions isn't the same in every session, but you haven't accounted for that in your batch script; etc. See MatlabProgramming for some more tips on reading m-files and so forth.