Loading EEG data from .mat file

  • MNE version: 0.24.1
  • operating system: Windows 10
data = loadmat('dataset_BCIcomp1.mat', struct_as_record=True)
EEGdata = data['x_train']
info = mne.create_info(ch_names = ['C3', 'Cz', 'C4'], sfreq= 128)  
raw = mne.io.RawArray(EEGdata, info)

I want to load that dataset, which is from BCI Competition III dataset 3. However, when I want to create a raw it gives me this error:

ValueError: Data must be a 2D array of shape (n_channels, n_samples), got shape (1152, 3, 140)
I have 3 channels and 140 trials
I used this code but it did not work

data = np.atleast_2d(data)

If the data is epoched, you can use mne.EpochsArray to directly create an Epochs object. Note that the shape of the input data must be (epochs, channels, times), so you probably need to transpose first (EEGdata.transpose(2, 1, 0)).

Thank you so much for your help. It works for me. I appreciate it.