EEGLab topoplot.m error

Hi Mike,

I am working on Chapter 9 of your book “Analyzing Neural Time Series Data”. There is a section of code generating Figure 9.4. It calls the EEGLAB Function totoplot.

— Your code generated the following error message ----

Unrecognized function or variable ‘icadefs’.

Error in topoplot (line 219)

Error in chapter09_Lesson (line 162)
[~,~,~,~,~,xi,yi,pltchans] = topoplot(zeros(64,1),EEG.chanlocs,‘electrodes’,‘off’,‘plotrad’,.53);
----- End of error message —

Background information

  • Matlab version: R2020b
  • EEGLab version: 2020_0
  • Windows 10
  • I have followed the instruction in your code: you need to modify the eeglab function ‘topoplot’. Replace the first line of code (the function definition) with: function [handle,Zi,grid,Xi,Yi,x,y,pltchans] = topoplot(Values,loc_file,varargin)
  • Image (png) of Matlab workspace showing the topoplot.m and variables, is attached.

Please advise how to fix it.

Thanks for helping!


Hi Larry. That looks like an eeglab initialization issue. I think you will need to initialize eeglab for the topoplot function (or any other eeglab functions) to work properly. That’s a feature of newer versions of eeglab compared to when I wrote the book.

Thus, I believe that if you type
eeglab; close
and then try the topoplot function again, it should work. Hopefully :wink:

Hi Mike,

Thanks for the reply. Your advice prompt me to include EEG function directory in the Matlab default path setup. After I did that, your code for figure 9.4 worked. However, the contour lines are not plotted in the figure on the right. Please help understand how to fix it.

Image is attached.


These are all settings in the topoplot function, which you can read about online or in the topoplot help file. I believe the key-value pair for that one is something like topoplot(…,‘numcontour’,6);


Yeap… after changing the parameter value of "numcontour’ to a non-zero value, the contour line showed up. Thanks!