Squeeze function does't reduce dimension!

Hi Mike,

Thanks for your amazing courses. I have a problem when I call the function plot_simEEG in “Complete neural signal processing and analysis: Zero to hero” course. I get an error in line 31 in the function with error message : Data cannot have more than 2 dimensions. Although I follow your instructions in the video lecture I still get the error.

Actually, I replaced with reshape function and fixed the error, however since you have used many times this function in your codes, I’d like to know why the squeeze function doesn’t remove dimension for me :)) . I use MATLAB version 2018a.


Hi Jafar. Please help me help you :wink: I’ll need some sample code or more descriptions of the sizes of the inputs you are using.

Thanks for your reply. Here are a piece of your code I use.

EEG.srate = 512; % sampling rate in Hz
EEG.pnts = EEG.srate*2;
EEG.trials = 60;
EEG.nbchan = 10;

% time vector
EEG.times = (0:EEG.pnts-1)/EEG.srate;
% create data as white noise
EEG.data = randn(EEG.nbchan,EEG.pnts,EEG.trials);


Error using plot
Data cannot have more than 2 dimensions.

Error in plot_simEEG (line 31)
h = plot(EEG.times,squeeze(EEG.data(chan,:,:)),‘linew’,.5);

Strange, it works fine for me with MATLAB 2019b. Which version do you have?

1 Like

I have 2018a.
When I generate a matrix, for instance, A=randn(10,1000,60) and then call squeeze B=squeeze(A(1,:,:)), the dimension of B should be 1000 * 60 as people say on the net but I get 1 * 1000 * 60.
Is it a problem with version of MATLAB? or I am wrong!:sweat_smile:

hmmm… try restarting MATLAB?? Or the computer? The known universe?

Thanks Mike, it seems there is something wrong with my matlab, I tested on another computer, your code works.