which columns of the .csv eeg file do I have to use to import it into EEGLAB?

32 views (last 30 days)
Hi everyone, I have saved my EEG data as a .csv file. The structure of the file can be seen in the Image, so I basically have a problem with the information within the columns. Is it correct if I extract the column with the time values and the columns with the data of the EEG channels and leave the column with the epochs? And I had problems with importing the .csv file in EEGLAB, so I saved the .csv file as a .mat file as you can see in the code below. I would really appreciate your help.
EEG = readtable('motor-imagery-1-[2023.11.23-15.14.58].csv');
EEG_nurKanaele = EEG(:,[1, 3:10]); % here the column with the time values and the columns with the EEG channels are extracted
EEG_matrix = table2array(EEG_nurKanaele); % Convert the table into a matrix
save('EEGDaten.mat', 'EEG_matrix'); % Save the matrix as a .mat file
  1 Comment
Taylor
Taylor on 30 Nov 2023
This question is probably better suited to the EEGLAB forum since it deals with specific usage of that tool, not just MATLAB in general.

Sign in to comment.

Answers (1)

Sanju
Sanju on 7 Dec 2023
It is correct to extract the column with the time values and the columns with the EEG channels and leave the column with the epochs. This is a common practice when working with EEG data. Saving the .csv file as a .mat file is also a good approach to import the data into EEGLAB.
However, there are a few things to consider and potentially improve in your code.
  • If the column with epochs is essential for your analysis, you might want to include it in EEG_matrix. Otherwise, if you don't need it, you can exclude it.
  • Ensure that the structure of your data in the .mat file is compatible with EEGLAB. EEGLAB often expects specific fields in the structure for time points, data, etc.
Here's an updated version of your code:
% Read the CSV file
EEG = readtable('motor-imagery-1-[2023.11.23-15.14.58].csv');
% Extract relevant columns (adjust column indices accordingly)
EEG_nurKanaele = EEG(:, [1, 3:10]); % Assuming columns 1, 3 to 10 are time and EEG channels
% Convert the table into a matrix
EEG_matrix = table2array(EEG_nurKanaele);
% Include the epochs column if needed
epochs_column = EEG(:, epoch_column_index); % Replace epoch_column_index with the actual index
EEG_matrix_with_epochs = [table2array(epochs_column), EEG_matrix];
% Save the matrix as a .mat file
save('EEGDaten.mat', 'EEG_matrix_with_epochs');
Make sure to replace epoch_column_index with the actual index of the epoch’s column in your CSV file.
Regarding EEGLAB, after saving the .mat file, you can try to import it using the EEGLAB graphical user interface (GUI) or using the “pop_loadset” function in your script as shown below,
% Load the EEG data into EEGLAB
EEG = pop_loadset('filename', 'EEGDaten.mat', 'filepath', '/path/to/directory/');
Adjust the file path accordingly.
Hope this Helps!

Categories

Find more on EEG/MEG/ECoG in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!