[Eeglablist] Merging two dataset

Ms Ritu Moni Borah ritu.b16 at nbrc.ac.in
Tue Oct 1 23:37:06 PDT 2024


Hello Niloofar,

Regarding your query on merging datasets while retaining the channels, you can achieve this by making a few adjustments to the pop_mergeset function. Specifically, the following lines of code (lines 191 to 214) can be modified:
original code(line 191 to 214)
 % Concatenate data
    % ----------------
    if INEEG1.trials > 1 || INEEG2.trials > 1
        INEEG1.data(:,:,end+1:end+size(INEEG2.data,3)) = INEEG2.data(:,:,:);
    else
        INEEG1.data(:,end+1:end+size(INEEG2.data,2)) = INEEG2.data(:,:);
    end

    INEEG1.setname = 'Merged datasets';
    INEEG1trials = INEEG1.trials;
    INEEG2trials = INEEG2.trials;
    INEEG1pnts   = INEEG1.pnts;
    INEEG2pnts   = INEEG2.pnts;

    if INEEG1.trials > 1 || INEEG2.trials > 1 % epoched data
        INEEG1.trials  =  INEEG1.trials + INEEG2.trials;

    else % continuous data
        INEEG1.pnts = INEEG1.pnts + INEEG2.pnts;
    end

modified lines

if INEEG1.pnts == INEEG2.pnts && INEEG1.trials == INEEG2.trials
    % Stack the channels from INEEG2 onto INEEG1 along the first dimension (channels)
    INEEG1.data = cat(1, INEEG1.data, INEEG2.data);
    
    % Update the number of channels to reflect the new stacked dataset
    INEEG1.nbchan = INEEG1.nbchan + INEEG2.nbchan;
    
    % Set the name of the merged dataset
    INEEG1.setname = 'Stacked datasets';
else
    error('Datasets must have the same number of time points and trials to stack channels.');
end

With this modification, the datasets will be merged along the channel dimension as requested.

As for your second query regarding the discrepancy in data points between the two datasets due to a delayed recording for one participant, you can resolve this by epoching the data before proceeding with the merge. This approach should help align the datasets appropriately.

Best

Ritu M Borah
PhD student
National Brain Research Centre, India

----- Original Message -----
From: eeglablist at sccn.ucsd.edu
To: eeglablist at sccn.ucsd.edu, eeglablist-bounces at sccn.ucsd.edu
Sent: Tuesday, September 24, 2024 12:47:15 PM
Subject: [Eeglablist] Merging two dataset

Hi dear community,

I have one problem that I could not solve myself. I have two eeg datasets, one for mother and one for infant. They are for eeg hyperscanning experiment. I recorded these two datasets with separate amplifiers and in separate files with brain recorder. As I should use a pipeline for analyzing my data, I should import infant and mother's data to MATLAB in one file and not separated. Therefore, I should merge my data. Bothe data has the same sampling rate 500 but there is two problems:

1.The name of the channels in two datasets are different
2.Data points in two datasets are different because I started recording for one of the participants with delay as I had two systems(they have the same number of markers)

I solved the channel's name. I changed the channels' name of one of the datasets to avoid any confusion. But I do not know how I can match the data point in two datasets and then I can merge them.

Below, it is a code that I am using for changing the channels' name and merging but it prefers one of the channels' names and ignores the channels' name of other dataset and then merges both datasets.





% Load EEGLAB
eeglab;

% Define file paths and file names for the first dataset
filepath1 = 'C:\Users\goharbakhsh\Desktop\EEG\ostracism hyper\original EEG data\New folder\New folder'; % Replace with your actual path
filename1 = 'infant.vhdr';       % Replace

% Load the first dataset
EEG1 = pop_loadbv(filepath1, filename1);



% Define file paths and file names for the second dataset
filepath2 = 'C:\Users\goharbakhsh\Desktop\EEG\ostracism hyper\original EEG data\New folder\New folder'; % Replace with your actual path
filename2 = 'mother.vhdr';       % Replace

% Load the second dataset
EEG2 = pop_loadbv(filepath2, filename2);




% Example: Add a prefix "m_" to all channels in EEG2
for i = 1:length(EEG2.chanlocs)
    EEG2.chanlocs(i).labels = ['m_' EEG2.chanlocs(i).labels];
end

% Display updated channel labels in EEG2
disp({EEG2.chanlocs.labels});



% Merge the two datasets
EEG_merged = pop_mergeset(EEG1, EEG2, 0);

% Saving mergeg data
pop_writebva(EEG, fullfile(outputPath, outputFilename));




The *vhdr file of the data should be in the format below for the pipelin. There are 64 channels, half of them is for the mothers and half is for infants.

[Channel Infos]
; Each entry: Ch<Channel number>=<Name>,<Reference channel name>,
; <Resolution in "Unit">,<Unit>, Future extensions..
; Fields are delimited by commas, some fields might be omitted (empty).
; Commas in channel names are coded as "\1".
Ch1=Fz,,0.1,µV
Ch2=F3,,0.1,µV
Ch3=F7,,0.1,µV
Ch4=F9,,0.1,µV
Ch5=FT7,,0.1,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,µV
Ch64=2_VEOG2,,0.1,µV



Do you have any ideas how can I marge my data to get this format?
Thank you very much for your time.


Kind regards,
Niloofar


----

Niloofar Goharbakhsh


PhD student in Developmental and Educational Psychology,
University of Bremen, Germany


_______________________________________________
Eeglablist page: http://sccn.ucsd.edu/eeglab/eeglabmail.html
To unsubscribe, send an empty email to eeglablist-unsubscribe at sccn.ucsd.edu
For digest mode, send an email with the subject "set digest mime" to eeglablist-request at sccn.ucsd.edu


More information about the eeglablist mailing list