eeghcommand. For further detail on the theoretical rationale behind these steps, please see the following paper:
eeghin to the command line and press enter. The following will be returned in the command window. This is a list of all of the functions run by EEGLAB during the preceeding analysis. These functions can be copied and pasted in to a script, which allows the user to repeat the analysis without using the EEGLAB interface. Under 'Home' press 'New Script' to open the editor and paste these functions in to the script. This script can now be saved for future use.
eeg_checkset. These functions are not necessary when running scripts as the data does not need to be stored for later access. It is better to save them to file (see below).
clear; close all; clc;to the top of the script. This clears all data from the workspace, closes any figures that are open and clears the command window. It's always good to start with a clean slate.
filepath = 'H:\\TESA_example_data\\test_TESA\\';). Instead of entering the full path as text in the load function, the variable filepath can now be entered instead. The same can be applied for the file name (coded as:
fileprefix = 'example_data';). Concatenation involves combining several strings together to make one string. This is useful for building file names (see save points below) and is coded as:
filename = [fileprefix, '.set'];The filename variable returns the following string: 'example_data.set'. Now if either the path where the data is stored or the name of the data changes (e.g. if you want to apply the same script to a different data file), changing the filepath and fileprefix at the top of the script will automatically apply these new names to the rest of the script.
EEG.allchan = EEG.chanlocs;). In the interpolation function (pop_interp), use this variable as input for the original channel locations (replace ALLEEG(2).chanlocs with EEG.allchan).
EEG = pop_rejchan(EEG, 'elec',[1:size(EEG.data,1)] ,'threshold',5,'norm','on','measure','kurt');. The command size(EEG.data,1) will return the size of the first dimension of the EEG data matrix, which corresponds to the electrode number. Therefore, if this script is used on a different data set with a different number of electrodes (e.g. not 62), it will still work.
EEG = pop_jointprob(EEG,1,[1:size(EEG.data,1)] ,5,5,0,0);. This will adapt the function to look for the number of channels present in the data. Change pop_rejepoch to
EEG = pop_rejepoch( EEG, EEG.BadTr ,0);. Above this line create a new line and enter the following:
EEG.BadTr = unique([find(EEG.reject.rejjp==1) find(EEG.reject.rejmanual==1)]);. These two lines will now save trials that have been automatically detected and manually marked in the EEG structure as EEG.BadTr and will then reject these epochs. Next, replace
EEG = eeg_rejsuperpose( EEG, 1, 1, 1, 1, 1, 1, 1, 1);with
pop_rejmenu(EEG,1);. This will plot the reject trials screen. Underneath this line, create a new line as follows:
pause_script = input('Highlight bad trials, update marks and then press enter');. This line will pause the script while you manually check through the trials (by pressing scroll data in the top right corner). When you have finished, press update marks and close the main trial rejection window (instead of pressing Reject marked trials). Now press enter in the command line and the script will continue. This is a bit clunky, but is necessary if you would like to manually check the trials. Note: The
inputfunction has changed in Matlab R2016a and will no longer allow the user to interactively access the figure while the script is paused. This works for Matlab R2015b and earlier.
filename = [fileprefix,'_cleaned.set'];Here the filename will be example_data_cleaned.set. Then include a line for saving using the EEGLAB save function.
EEG = pop_saveset( EEG, 'filename',filename,'filepath',filepath);
pop_chaneditmay need to be altered depending on where the eeglab folder is stored.