### Start EEGLAB Source: https://github.com/sccn/eeglab/blob/develop/sample_locs/1ST_README.txt Start the EEGLAB environment in Matlab. This is sometimes necessary before using EEGLAB functions like pop_chanedit. ```matlab >> eeglab ``` -------------------------------- ### eeglab Source: https://context7.com/sccn/eeglab/llms.txt Launches the EEGLAB environment or controls its state. It can start the GUI, run in headless mode for scripting, display version information, load tutorial datasets, or rebuild the GUI window. ```APIDOC ## eeglab ### Description Launches the EEGLAB GUI, controls its state, or displays version information. ### Usage ```matlab % Start EEGLAB GUI eeglab; % Start without GUI (for scripting) eeglab nogui; % Print the current version eeglab versions; % Load tutorial continuous dataset and refresh the GUI eeglab continuous; % Load tutorial epoched dataset eeglab epoch; % Force rebuild the EEGLAB window eeglab rebuild; ``` ``` -------------------------------- ### Install EEGLAB Plugins Programmatically Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md Install EEGLAB plugins silently without user prompts. Specify the plugin name and its main function. ```matlab plugin_askinstall('ICLabel', 'iclabel', 0); plugin_askinstall('clean_rawdata', 'clean_artifacts', 0); plugin_askinstall('firfilt', 'pop_eegfiltnew', 0); plugin_askinstall('picard', 'picard', 0); plugin_askinstall('dipfit', 'pop_dipfit_settings', 0); ``` -------------------------------- ### Launch or control EEGLAB environment Source: https://context7.com/sccn/eeglab/llms.txt Use the `eeglab` function to start the EEGLAB GUI, run in headless mode for scripting, check the version, load tutorial datasets, or rebuild the GUI window. ```matlab % Start EEGLAB GUI eeglab; ``` ```matlab % Start without GUI (for scripting) eeglab nogui; ``` ```matlab % Print the current version eeglab versions; % Output: EEGLAB v2026.0.0 ``` ```matlab % Load tutorial continuous dataset and refresh the GUI eeglab continuous; ``` ```matlab % Load tutorial epoched dataset eeglab epoch; ``` ```matlab % Force rebuild the EEGLAB window eeglab rebuild; ``` -------------------------------- ### Clone EEGLAB with Submodules Source: https://github.com/sccn/eeglab/blob/develop/README.md Use this command to clone the EEGLAB repository and its submodules. Ensure you have Git installed and configured. ```bash git clone --recurse-submodules https://github.com/sccn/eeglab.git ``` -------------------------------- ### Minimal EEGLAB Plugin Registration Function Source: https://context7.com/sccn/eeglab/llms.txt This is a minimal example of an EEGLAB plugin registration function. Save it as `eegplugin_.m` inside a plugin folder (e.g., `plugins/myplugin1.0/`). It defines the plugin version and adds a custom menu item to the EEGLAB interface. ```matlab % Minimal plugin registration function (save as eegplugin_myplugin.m % inside plugins/myplugin1.0/) function vers = eegplugin_myplugin(fig, try_strings, catch_strings) vers = 'myplugin1.0'; % returned version string % Build the menu callback using EEGLAB's try/catch wrapper strings % try_strings.check_data - checks EEG.data exists before running % catch_strings.new_and_hist - stores result and adds to history cb = [try_strings.check_data ... '[EEG, LASTCOM] = my_processing_func(EEG);' catch_strings.new_and_hist]; % Add a menu item under "Tools" toolsmenu = findobj(fig, 'Label', 'Tools'); uimenu(toolsmenu, ... 'Label', 'Run My Processing', 'Callback', cb, ... 'Separator', 'on'); end % To install: place the plugin folder under eeglab/plugins/ and restart EEGLAB % EEGLAB then prints: EEGLAB: adding "myplugin" v1.0 (see >> help eegplugin_myplugin) ``` -------------------------------- ### Convert Electrode Locations using EEGLAB Source: https://github.com/sccn/eeglab/blob/develop/sample_locs/1ST_README.txt Use this command to open the EEGLAB channel editor and convert electrode location files. Ensure EEGLAB is started first if Matlab cannot find the function. ```matlab >> pop_chanedit(readlocs('Standard-10-20-Cap81.ced')); ``` -------------------------------- ### Create Simple Input GUI with inputgui Source: https://github.com/sccn/eeglab/blob/develop/functions/guifunc/README.txt Use inputgui to create a basic graphical interface for user input. The 'geometry' and 'uilist' parameters define the layout and content of the input fields. ```matlab [res userdat strhalt restag] = inputgui('geometry', { 1 1 }, 'uilist', ... { { 'style' 'text' 'string' 'Enter a value' } ... { 'style' 'edit' 'string' '' 'tag' 'editstr'} }); ``` -------------------------------- ### Manage Datasets with eeg_store and eeg_retrieve Source: https://context7.com/sccn/eeglab/llms.txt Use `eeg_store` to save the current EEG dataset into the global `ALLEEG` array, either automatically selecting a slot or overwriting a specific one. `eeg_retrieve` loads a dataset from `ALLEEG` into the active `EEG` variable. ```matlab [ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, 0); ``` ```matlab [ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET); ``` ```matlab [ALLEEG, EEG] = eeg_store(ALLEEG, EEG, 3); ``` ```matlab [EEG, ALLEEG] = eeg_retrieve(ALLEEG, 2); CURRENTSET = 2; ``` -------------------------------- ### Standard Preprocessing Pipeline for ERP Analysis Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md This pipeline outlines the recommended order of operations for ERP analysis, including data loading, channel editing, artifact rejection, ICA, component classification, epoch extraction, baseline removal, and saving. Ensure correct file paths and channel names are used. ```matlab EEG = pop_loadset('filename', 'data.set', 'filepath', '/path/'); % or: EEG = pop_fileio('/path/to/data.edf'); % or: [STUDY, ALLEEG] = pop_importbids(bidspath, 'studyName', 'MyStudy'); ``` ```matlab EEG = pop_chanedit(EEG, 'lookup', 'standard-10-5-cap385.elp'); ``` ```matlab EEG = pop_select(EEG, 'nochannel', {'EXG1','EXG2','EXG3','ECG','EMG'}); ``` ```matlab EEG = pop_reref(EEG, []); ``` ```matlab EEG = pop_clean_rawdata(EEG, \ 'FlatlineCriterion', 5, \ 'ChannelCriterion', 0.8, \ 'LineNoiseCriterion', 4, \ 'Highpass', [0.25 0.75], \ 'BurstCriterion', 20, \ 'WindowCriterion', 0.25, \ 'BurstRejection', 'on', \ 'Distance', 'Euclidian', \ 'WindowCriterionTolerances', [-Inf 7]); ``` ```matlab EEG = pop_reref(EEG, []); ``` ```matlab % 7. Run ICA (pca -1 = auto-reduce for rank-deficient data) % 'pca', -1 indicate to reduce the dimension by 1 to account for rank decrease by average reference in 6 EEG = pop_runica(EEG, 'icatype', 'runica', 'options', {'pca', -1}); ``` ```matlab % 8. Classify and flag artifact components (ICLabel) EEG = pop_iclabel(EEG, 'default'); EEG = pop_icflag(EEG, [NaN NaN; 0.9 1; 0.9 1; NaN NaN; NaN NaN; NaN NaN; NaN NaN]); % Brain Muscle Eye Heart LineNoise ChanNoise Other ``` ```matlab % 9. Remove flagged components EEG = pop_subcomp(EEG, find(EEG.reject.gcompreject), 0); ``` ```matlab % 10. Extract epochs EEG = pop_epoch(EEG, {'xxx','yyy'}, [-1 2], 'epochinfo', 'yes'); EEG = eeg_checkset(EEG); ``` ```matlab % 11. Remove baseline EEG = pop_rmbase(EEG, [-1000 0]); ``` ```matlab % 12. Save EEG = pop_saveset(EEG, 'filename', 'processed.set', 'filepath', '/path/'); ``` -------------------------------- ### Load saved EEGLAB dataset (.set file) Source: https://context7.com/sccn/eeglab/llms.txt The `pop_loadset` function loads EEGLAB datasets from `.set` files. It can load the full dataset, only metadata ('info' mode), or multiple datasets into an array. ```matlab % Load a single dataset (full data + structure) EEG = pop_loadset('filename', 'subject01.set', 'filepath', '/data/'); ``` ```matlab % Load only the dataset structure without data (useful for inspecting metadata) EEG = pop_loadset('filename', 'subject01.set', 'filepath', '/data/', ... 'loadmode', 'info'); disp(EEG.nbchan) % channel count available even without data ``` ```matlab % Load multiple datasets at once into an array EEG = pop_loadset('filename', {'sub01.set','sub02.set'}, ... 'filepath', '/data/'); % EEG(1) and EEG(2) are separate dataset structures ``` ```matlab % Old-style (positional) calling convention EEG = pop_loadset('subject01.set', '/data/'); ``` -------------------------------- ### Create STUDY from BIDS Data Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md Initiate a STUDY structure from BIDS data using pop_importbids. Options include specifying event types, importing channel locations, and naming the study. ```matlab [STUDY, ALLEEG] = pop_importbids(filepath, 'eventtype', 'trial_type', 'bidsevent', 'on', 'bidschanloc', 'on', 'studyName', 'MyStudy'); ``` -------------------------------- ### pop_loadset Source: https://context7.com/sccn/eeglab/llms.txt Loads a saved EEGLAB dataset (.set file) from disk into the EEG structure. It can load the full dataset, only metadata, or multiple datasets at once. ```APIDOC ## pop_loadset ### Description Loads a saved EEGLAB dataset (.set file) from disk into the `EEG` structure. It can load the full dataset, only metadata, or multiple datasets at once. ### Usage ```matlab % Load a single dataset (full data + structure) EEG = pop_loadset('filename', 'subject01.set', 'filepath', '/data/'); % Load only the dataset structure without data (useful for inspecting metadata) EEG = pop_loadset('filename', 'subject01.set', 'filepath', '/data/', ... 'loadmode', 'info'); disp(EEG.nbchan) % channel count available even without data % Load multiple datasets at once into an array EEG = pop_loadset('filename', {'sub01.set','sub02.set'}, ... 'filepath', '/data/'); % EEG(1) and EEG(2) are separate dataset structures % Old-style (positional) calling convention EEG = pop_loadset('subject01.set', '/data/'); ``` ``` -------------------------------- ### Create or Edit Multi-Subject STUDY with pop_study Source: https://context7.com/sccn/eeglab/llms.txt Assembles a STUDY structure for group-level analysis, grouping datasets by subject, condition, session, and group. Use 'gui' 'off' for scripting or 'on' for interactive editing. The 'add' parameter allows programmatic definition of dataset properties. ```matlab % Create a new STUDY from all datasets currently in ALLEEG [STUDY, ALLEEG] = pop_study([], ALLEEG, 'gui', 'off', 'name', 'Auditory Oddball', 'task', 'Three-stimulus oddball', 'notes', 'N=20 healthy adults', 'filename', 'oddball.study', 'filepath', '/data/studies/', 'add', { ... {1 'subject' 'S01' 'condition' 'target' 'session' 1 'group' 'control'} {2 'subject' 'S01' 'condition' 'standard' 'session' 1 'group' 'control'} {3 'subject' 'S02' 'condition' 'target' 'session' 1 'group' 'control'} {4 'subject' 'S02' 'condition' 'standard' 'session' 1 'group' 'control'} }); % Edit an existing STUDY interactively [STUDY, ALLEEG] = pop_study(STUDY, ALLEEG, 'gui', 'on'); % Inspect the STUDY structure fprintf('Subjects: %s\n', strjoin(STUDY.subject, ', ')); fprintf('Conditions: %s\n', strjoin(STUDY.condition, ', ')); fprintf('Datasets: %d\n', length(STUDY.datasetinfo)); ``` -------------------------------- ### Import Events from File Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md Use pop_importevent to load event data from a text file. Specify the file path and the fields to import, such as 'latency' and 'type'. ```matlab EEG = pop_importevent(EEG, 'event', 'events.txt', 'fields', {'latency','type'}); ``` -------------------------------- ### Apply FIR Filters using pop_eegfiltnew Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md Use pop_eegfiltnew for FIR filtering. Specify 'locutoff' for high-pass and 'hicutoff' for low-pass filtering. This is the preferred method. ```matlab EEG = pop_eegfiltnew(EEG, 'locutoff', 1); % 1 Hz high-pass EEG = pop_eegfiltnew(EEG, 'hicutoff', 40); % 40 Hz low-pass EEG = pop_eegfiltnew(EEG, 'locutoff', 1, 'hicutoff', 40); % Bandpass ``` -------------------------------- ### Update EEGLAB Submodules Source: https://github.com/sccn/eeglab/blob/develop/README.md If you forgot to clone submodules initially, navigate to the EEGLAB directory and run these commands to update them. This is also useful for ensuring you have the latest submodule versions. ```bash git submodule update --init --recursive --remote git pull --recurse-submodules ``` -------------------------------- ### Commit with Multi-line Message Source: https://github.com/sccn/eeglab/blob/develop/CONTRIBUTING.md Use this command to create a Git commit with a synopsis and a detailed message body, separated by two newlines. This format is recognized by GitHub for parsing commit messages. ```bash $ git commit -m $'Commit synopsis\n\nHere is a much longer and wordier description of my proposed changes that doesn\'t fit into 80 characters.\nI can even spread the message body across multiple lines.' ``` -------------------------------- ### pop_saveset Source: https://context7.com/sccn/eeglab/llms.txt Save an EEG dataset to disk. Writes the EEG structure to a .set file, optionally writing data to a separate binary .fdt file. ```APIDOC ## pop_saveset — Save an EEG dataset to disk ### Description Writes the `EEG` structure to a `.set` file, optionally writing data to a separate binary `.fdt` file. ### Method MATLAB Function ### Parameters - **EEG** (struct) - The EEG structure to save. - **filename** (string) - Optional. The name of the file to save. - **filepath** (string) - Optional. The directory to save the file in. - **savemode** (string) - Optional. Can be 'onefile' (data embedded in .set), 'twofiles' (.set + .fdt), or 'resave' (save to current location). - **check** (string) - Optional. Enable consistency check ('on' or 'off'). - **version** (string) - Optional. Matlab version format (e.g., '7.3' for HDF5). ### Request Example ```matlab % Save to a new file (one-file format, data embedded in .set) EEG = pop_saveset(EEG, 'filename', 'subject01_filtered.set', ... 'filepath', '/data/processed/', ... 'savemode', 'onefile'); % Save as two files: .set (structure) + .fdt (binary data) — memory efficient EEG = pop_saveset(EEG, 'filename', 'subject01_filtered.set', ... 'filepath', '/data/processed/', ... 'savemode', 'twofiles'); % Resave to the same location already stored in EEG.filepath/EEG.filename EEG = pop_saveset(EEG, 'savemode', 'resave'); % Save with extended consistency check and Matlab 7.3 format (HDF5, large files) EEG = pop_saveset(EEG, 'filename', 'large_dataset.set', ... 'filepath', '/data/', ... 'check', 'on', 'version', '7.3'); ``` ``` -------------------------------- ### Run MATLAB in Batch Mode Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md Execute MATLAB commands non-interactively for automation. Use the `-batch` flag followed by the desired command. ```bash /Applications/MATLAB_R2025a.app/bin/matlab -batch "command_here" ``` ```bash /Applications/MATLAB_R2025a.app/bin/matlab -batch "cd('/Users/arno/GitHub/core_eeg/eeglab'); eeglab nogui; your_script" ``` -------------------------------- ### Compute Paired T-test with Statcond Source: https://github.com/sccn/eeglab/blob/develop/functions/statistics/README.txt Demonstrates computing a paired t-test between two conditions using the statcond function. It shows both parametric and resampling (bootstrap and permutation) modes. For resampling, specify 'mode' and 'naccu' for the number of accurate repetitions. ```matlab cond1 = rand(100,64,10); cond2 = rand(100,64,10)+0.2; ``` ```matlab [t df p] = statcond({ cond1 cond2 }); ``` ```matlab [t df p] = statcond({ cond1 cond2 }, 'mode', 'bootstrap', 'naccu', 1000); ``` ```matlab [t df p] = statcond({ cond1 cond2 }, 'mode', 'perm', 'naccu', 1000); ``` -------------------------------- ### Save EEG Dataset with pop_saveset Source: https://context7.com/sccn/eeglab/llms.txt Use `pop_saveset` to save EEG data. Specify 'onefile' to embed binary data in the .set file, or 'twofiles' for separate .set and .fdt files for memory efficiency. 'resave' updates the existing file. Use 'check on' and 'version 7.3' for large datasets with extended checks. ```matlab EEG = pop_saveset(EEG, 'filename', 'subject01_filtered.set', 'filepath', '/data/processed/', 'savemode', 'onefile'); ``` ```matlab EEG = pop_saveset(EEG, 'filename', 'subject01_filtered.set', 'filepath', '/data/processed/', 'savemode', 'twofiles'); ``` ```matlab EEG = pop_saveset(EEG, 'savemode', 'resave'); ``` ```matlab EEG = pop_saveset(EEG, 'filename', 'large_dataset.set', 'filepath', '/data/', 'check', 'on', 'version', '7.3'); ``` -------------------------------- ### pop_study Source: https://context7.com/sccn/eeglab/llms.txt Assembles a STUDY structure grouping multiple EEG datasets by subject, condition, session, and group for group-level statistical analysis. ```APIDOC ## pop_study — Create or edit a multi-subject STUDY ### Description Assembles a STUDY structure grouping multiple EEG datasets by subject, condition, session, and group for group-level statistical analysis. ### Usage Examples ```matlab % Create a new STUDY from all datasets currently in ALLEEG [STUDY, ALLEEG] = pop_study([], ALLEEG, 'gui', 'off', 'name', 'Auditory Oddball', 'task', 'Three-stimulus oddball', 'notes', 'N=20 healthy adults', 'filename', 'oddball.study', 'filepath', '/data/studies/', 'add', { ... {1 'subject' 'S01' 'condition' 'target' 'session' 1 'group' 'control'} {2 'subject' 'S01' 'condition' 'standard' 'session' 1 'group' 'control'} {3 'subject' 'S02' 'condition' 'target' 'session' 1 'group' 'control'} {4 'subject' 'S02' 'condition' 'standard' 'session' 1 'group' 'control'} }); % Edit an existing STUDY interactively [STUDY, ALLEEG] = pop_study(STUDY, ALLEEG, 'gui', 'on'); % Inspect the STUDY structure fprintf('Subjects: %s\n', strjoin(STUDY.subject, ', ')); fprintf('Conditions: %s\n', strjoin(STUDY.condition, ', ')); fprintf('Datasets: %d\n', length(STUDY.datasetinfo)); ``` ``` -------------------------------- ### Create Input GUI with Complex Geometry Source: https://github.com/sccn/eeglab/blob/develop/functions/guifunc/README.txt Define complex layouts for GUI elements using the 'geom' input in inputgui, similar to MATLAB's subplot function. This allows for precise control over element positioning and sizing. ```matlab res = inputgui('geom', { {2 1 [0 0] [1 1]} {2 1 [1 0] [1 1]} }, 'uilist', { { 'style' 'text' 'string' 'Enter a value' } ... { 'style' 'edit' 'string' '' } }); ``` -------------------------------- ### eeg_store / eeg_retrieve Source: https://context7.com/sccn/eeglab/llms.txt Manage the ALLEEG dataset array. Store a processed dataset back into the ALLEEG global array, or retrieve a specific dataset from it. ```APIDOC ## eeg_store / eeg_retrieve — Manage the ALLEEG dataset array ### Description Store a processed dataset back into the ALLEEG global array, or retrieve a specific dataset from it. ### Method MATLAB Function ### Parameters - **ALLEEG** (struct) - The ALLEEG global array. - **EEG** (struct) - The EEG dataset to store or retrieve. - **index** (numeric) - The index in ALLEEG to store/retrieve from. Use 0 for auto-selection during store. ### Return Values - **ALLEEG** (struct) - The updated ALLEEG array. - **EEG** (struct) - The retrieved or stored EEG dataset. - **CURRENTSET** (numeric) - The index of the current dataset in ALLEEG. ### Request Example ```matlab % Store the current EEG dataset into ALLEEG (auto-select slot) [ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, 0); % CURRENTSET holds the assigned index % Overwrite the current slot in ALLEEG with the modified EEG [ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET); % Store into a specific slot (e.g. slot 3) [ALLEEG, EEG] = eeg_store(ALLEEG, EEG, 3); % Retrieve dataset 2 from ALLEEG as the active dataset [EEG, ALLEEG] = eeg_retrieve(ALLEEG, 2); CURRENTSET = 2; ``` ``` -------------------------------- ### eeg_getversion Source: https://context7.com/sccn/eeglab/llms.txt Retrieves the EEGLAB version string and optionally a numeric representation and release date for version comparisons. ```APIDOC ## eeg_getversion ### Description Retrieves the EEGLAB version string and optional numeric representation. ### Usage ```matlab % Get version string only vers = eeg_getversion(); % Get version string and numeric value [vers, vnum, releaseDate] = eeg_getversion(); % Conditional version check in a script [~, vnum] = eeg_getversion(); if vnum < 2024 error('EEGLAB 2024 or newer required'); end ``` ``` -------------------------------- ### pop_importdata Source: https://context7.com/sccn/eeglab/llms.txt Imports EEG data from various sources (Matlab variable, ASCII, binary float) into an EEGLAB EEG structure. It supports headless operation with key-value pairs. ```APIDOC ## pop_importdata ### Description Imports EEG data from a Matlab variable, ASCII file, or binary float file and constructs the `EEG` structure. Accepts `'key', value` pairs for headless use. ### Usage ```matlab % Import a Matlab variable already in the workspace % mydata is a [channels x timepoints] matrix mydata = randn(64, 30000); % 64 channels, 30000 samples EEG = pop_importdata(... 'setname', 'My EEG recording', ... 'data', 'mydata', ... % workspace variable name 'dataformat', 'array', ... 'srate', 256, ... % sampling rate in Hz 'chanlocs', 'standard-10-20.locs', ... 'subject', 'S01', ... 'condition', 'rest'); % Verify the structure disp(EEG.nbchan) % 64 disp(EEG.srate) % 256 disp(EEG.pnts) % 30000 % Import from a float32 binary file EEG = pop_importdata(... 'setname', 'Recorded EEG', ... 'data', '/data/subject01.fdt', ... 'dataformat', 'float32le', ... 'nbchan', 64, ... 'srate', 512, ... 'xmin', 0); ``` ``` -------------------------------- ### Select Data Subsets with pop_select Source: https://context7.com/sccn/eeglab/llms.txt Returns a new dataset by retaining or excluding specific channels, time ranges, or epoch indices. Supports selection by channel number, label, epoch index, and continuous time windows. ```matlab % Retain only channels 1–64 (remove auxiliary channels) EEG = pop_select(EEG, 'channel', 1:64); ``` ```matlab % Keep channels by label EEG = pop_select(EEG, 'channel', {'Fp1','Fp2','F3','F4','Fz', 'C3','C4','Cz','P3','P4','Pz'}); ``` ```matlab % Remove channels by label (exclude EOG and EMG) EEG = pop_select(EEG, 'nochannel', {'EOG1','EOG2','EMG1','EMG2'}); ``` ```matlab % Keep only epochs 10–50 EEG = pop_select(EEG, 'trial', 10:50); ``` ```matlab % Keep continuous data from 30 s to 120 s EEG = pop_select(EEG, 'time', [30 120]); ``` ```matlab % Keep two time windows of continuous data EEG = pop_select(EEG, 'time', [10 60; 70 120]); ``` ```matlab % Trim each epoch to [-100 500] ms EEG = pop_select(EEG, 'time', [-0.1 0.5]); % in seconds ``` -------------------------------- ### Display Question Dialog with questdlg2 Source: https://github.com/sccn/eeglab/blob/develop/functions/guifunc/README.txt Replace the standard MATLAB questdlg function with questdlg2 for customizable question dialogs. This function allows specifying default answers and button labels. ```matlab ButtonName = questdlg2('What is your favorite color?', 'Color Question', ... 'Red', 'Green', 'Blue', 'Green'); ``` -------------------------------- ### pop_spectopo Source: https://context7.com/sccn/eeglab/llms.txt Computes and plots power spectral density (PSD) for all channels and overlays topographic maps at selected frequencies. ```APIDOC ## pop_spectopo — Plot channel or component power spectra and scalp maps ### Description Computes and plots power spectral density (PSD) for all channels and overlays topographic maps at selected frequencies. ### Usage Examples ```matlab % Plot channel spectra for the full dataset, show topo maps at 10, 20, 30 Hz pop_spectopo(EEG, 1, [], 'EEG', 'freqs', [10 20 30], 'freqrange', [1 50], 'percent', 100); % Plot spectra using 50 % of data (faster) pop_spectopo(EEG, 1, [], 'EEG', 'percent', 50, 'freqrange', [1 80]); % Plot component spectra and show the 3 components contributing most at 10 Hz pop_spectopo(EEG, 0, [], 'EEG', % dataflag=0 -> components 'freqs', [10], 'nicamaps', 3, 'freqrange', [1 50]); % Capture output: spectra matrix, frequencies, components, etc. [spectra, freqs, speccomp, contrib] = pop_spectopo(EEG, 1, [0 EEG.xmax*1000]); % spectra: [nchans x nfreqs], freqs: [1 x nfreqs] ``` ``` -------------------------------- ### Retrieve EEGLAB version information Source: https://context7.com/sccn/eeglab/llms.txt The `eeg_getversion` function returns the EEGLAB version string and optionally a numeric representation and release date. Useful for conditional logic in scripts. ```matlab % Get version string only vers = eeg_getversion(); % vers = '2026.0.0' ``` ```matlab % Get version string and numeric value [vers, vnum, releaseDate] = eeg_getversion(); % vers = '2026.0.0' % vnum = 2026 (numeric, for comparisons) % releaseDate = '14-Feb-2026 14:55:42' ``` ```matlab % Conditional version check in a script [~, vnum] = eeg_getversion(); if vnum < 2024 error('EEGLAB 2024 or newer required'); end ``` -------------------------------- ### Plot ERP Data Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md Configure ERP plotting parameters with pop_erpparams and then generate the plot using std_erpplot. Specify channels and the design to use for plotting. ```matlab STUDY = pop_erpparams(STUDY, 'topotime', 350); STUDY = std_erpplot(STUDY, ALLEEG, 'channels', {ALLEEG(1).chanlocs.labels}, 'design', 1); ``` -------------------------------- ### Plot Power Spectra and Scalp Maps with pop_spectopo Source: https://context7.com/sccn/eeglab/llms.txt Computes and plots power spectral density (PSD) for channels or components, overlaying topographic maps at specified frequencies. Use 'percent' to control the data fraction used for computation, affecting speed and accuracy. ```matlab % Plot channel spectra for the full dataset, show topo maps at 10, 20, 30 Hz pop_spectopo(EEG, 1, [], 'EEG', 'freqs', [10 20 30], 'freqrange', [1 50], 'percent', 100); % Plot spectra using 50 % of data (faster) pop_spectopo(EEG, 1, [], 'EEG', 'percent', 50, 'freqrange', [1 80]); % Plot component spectra and show the 3 components contributing most at 10 Hz pop_spectopo(EEG, 0, [], 'EEG', ... % dataflag=0 -> components 'freqs', [10], 'nicamaps', 3, 'freqrange', [1 50]); % Capture output: spectra matrix, frequencies, components, etc. [spectra, freqs, speccomp, contrib] = pop_spectopo(EEG, 1, [0 EEG.xmax*1000]); % spectra: [nchans x nfreqs], freqs: [1 x nfreqs] ``` -------------------------------- ### Add New Events Programmatically Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md This script demonstrates how to add new events to the EEG structure by iterating through existing events and creating new ones based on specific criteria. Ensure event consistency after modification using eeg_checkset. ```matlab for i = 1:length(EEG.event) if strcmpi(EEG.event(i).type, 'stimulus') EEG.event(end+1) = EEG.event(i); EEG.event(end).latency = EEG.event(i).latency - 0.1*EEG.srate; % 100ms before EEG.event(end).type = 'cue'; end end EEG = eeg_checkset(EEG, 'eventconsistency'); ``` -------------------------------- ### Import raw data into EEG structure Source: https://context7.com/sccn/eeglab/llms.txt Use `pop_importdata` to import EEG data from Matlab variables, ASCII, or binary files into an `EEG` structure. Supports headless operation with key-value pairs. ```matlab % Import a Matlab variable already in the workspace % mydata is a [channels x timepoints] matrix mydata = randn(64, 30000); % 64 channels, 30000 samples EEG = pop_importdata( ... 'setname', 'My EEG recording', ... 'data', 'mydata', ... % workspace variable name 'dataformat', 'array', 'srate', 256, ... % sampling rate in Hz 'chanlocs', 'standard-10-20.locs', ... 'subject', 'S01', ... 'condition', 'rest'); % Verify the structure disp(EEG.nbchan) % 64 disp(EEG.srate) % 256 disp(EEG.pnts) % 30000 ``` ```matlab % Import from a float32 binary file EEG = pop_importdata( ... 'setname', 'Recorded EEG', ... 'data', '/data/subject01.fdt', ... 'dataformat', 'float32le', ... 'nbchan', 64, ... 'srate', 512, ... 'xmin', 0); ``` -------------------------------- ### Apply Legacy FIR Filter using pop_eegfilt Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md The legacy pop_eegfilt function can also be used for FIR filtering. Note the different argument order for high-pass and low-pass. ```matlab EEG = pop_eegfilt(EEG, 1, 0); % 1 Hz high-pass EEG = pop_eegfilt(EEG, 0, 40); % 40 Hz low-pass ``` -------------------------------- ### Create STUDY Design Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md Define a STUDY design using std_makedesign. This involves specifying the dataset, design name, and variables with their types and values. ```matlab STUDY = std_makedesign(STUDY, ALLEEG, 1, 'name', 'Design1', 'variable1', 'type', 'values1', {'target','standard'}, 'vartype1', 'categorical', 'subjselect', STUDY.subject); ``` -------------------------------- ### Re-reference EEG Data with pop_reref Source: https://context7.com/sccn/eeglab/llms.txt Re-reference EEG data using `pop_reref`. Options include average reference (pass `[]`), referencing a specific electrode by index or name, or using a pair of electrodes. Channels can be excluded, and the old reference can be kept. ICA decompositions can be removed during re-referencing. ```matlab EEG = pop_reref(EEG, []); ``` ```matlab EEG = pop_reref(EEG, 48); ``` ```matlab EEG = pop_reref(EEG, 'Cz'); ``` ```matlab EEG = pop_reref(EEG, [65 66], 'keepref', 'on'); ``` ```matlab EEG = pop_reref(EEG, [], 'exclude', [65 66 67 68]); ``` ```matlab EEG = pop_reref(EEG, [], 'refica', 'remove'); ``` -------------------------------- ### Event-Related Time-Frequency Analysis with pop_newtimef Source: https://context7.com/sccn/eeglab/llms.txt Performs event-related spectral perturbation (ERSP) and inter-trial coherence (ITC) using wavelet decomposition or FFT. Specify 'typeplot' to analyze channels (1) or components (0). Use 'plotersp' and 'plotitc' to control output plotting. ```matlab % Time-frequency decomposition of channel 10 (Cz), default settings pop_newtimef(EEG, 1, 10); % typeplot=1 -> channel data % Channel 10, specify epoch window, 3–50 Hz, 3–0.5 wavelet cycles pop_newtimef(EEG, 1, 10, [-500 800], [3 0.5], ... 'freqs', [3 50], 'baseline', [-200 0], 'plotitc', 'on'); % Component 2 time-frequency (typeplot=0) pop_newtimef(EEG, 0, 2, [-500 800], [3 0.5], ... 'freqscale', 'log', 'alpha', 0.05); % mask non-significant at p<0.05 % Return ERSP and ITC matrices without plotting [ersp, itc, ~, times, freqs] = pop_newtimef(EEG, 1, 10, ... [-500 800], [3 0.5], 'plotersp', 'off', 'plotitc', 'off'); % ersp: [nfreqs x ntimes], itc: [nfreqs x ntimes] fprintf('ERSP size: %d freqs x %d times\n', length(freqs), length(times)); ``` -------------------------------- ### pop_newtimef Source: https://context7.com/sccn/eeglab/llms.txt Computes and plots event-related spectral perturbation (ERSP) and inter-trial coherence (ITC) for a single channel or component using wavelet decomposition or FFT. ```APIDOC ## pop_newtimef — Event-related time-frequency analysis (ERSP / ITC) ### Description Computes and plots event-related spectral perturbation (ERSP) and inter-trial coherence (ITC) for a single channel or component using wavelet decomposition or FFT. ### Usage Examples ```matlab % Time-frequency decomposition of channel 10 (Cz), default settings pop_newtimef(EEG, 1, 10); % typeplot=1 -> channel data % Channel 10, specify epoch window, 3–50 Hz, 3–0.5 wavelet cycles pop_newtimef(EEG, 1, 10, [-500 800], [3 0.5], 'freqs', [3 50], 'baseline', [-200 0], 'plotitc', 'on'); % Component 2 time-frequency (typeplot=0) pop_newtimef(EEG, 0, 2, [-500 800], [3 0.5], 'freqscale', 'log', 'alpha', 0.05); % mask non-significant at p<0.05 % Return ERSP and ITC matrices without plotting [ersp, itc, ~, times, freqs] = pop_newtimef(EEG, 1, 10, [-500 800], [3 0.5], 'plotersp', 'off', 'plotitc', 'off'); % ersp: [nfreqs x ntimes], itc: [nfreqs x ntimes] fprintf('ERSP size: %d freqs x %d times\n', length(freqs), length(times)); ``` ``` -------------------------------- ### Apply FIR Filter with pop_eegfilt Source: https://context7.com/sccn/eeglab/llms.txt Apply FIR filters (highpass, lowpass, bandpass, notch) to EEG data using `pop_eegfilt`. Set cutoff frequencies to 0 to skip a filter type. A notch filter can be applied by passing a range like [45 55] and setting `revfilt` to 1. An optional filter order and plotting of the frequency response are available. ```matlab EEG = pop_eegfilt(EEG, 1, 0); ``` ```matlab EEG = pop_eegfilt(EEG, 0, 40); ``` ```matlab EEG = pop_eegfilt(EEG, 1, 40); ``` ```matlab EEG = pop_eegfilt(EEG, 45, 55, [], 1); ``` ```matlab filtorder = 3 * fix(EEG.srate / 0.5); EEG = pop_eegfilt(EEG, 0.5, 100, filtorder, 0, 0, 1); ``` -------------------------------- ### Precompute Measures for STUDY Source: https://github.com/sccn/eeglab/blob/develop/CLAUDE.md Use std_precomp to precompute various measures for a STUDY. Options include saving trials, removing ICA components, interpolating channels, and recomputing ERPs. ```matlab [STUDY, ALLEEG] = std_precomp(STUDY, ALLEEG, {}, 'savetrials', 'on', 'rmicacomps', 'on', 'interp', 'on', 'recompute', 'on', 'erp', 'on'); ``` -------------------------------- ### pop_select Source: https://context7.com/sccn/eeglab/llms.txt Selects subsets of EEG data based on channels, time ranges, or epoch indices. It can retain or exclude specific data portions and supports selection by channel labels or time windows. ```APIDOC ## pop_select — Select subsets of data (channels, time, epochs) ### Description Returns a new dataset retaining or excluding specific channels, time ranges, or epoch indices. ### Usage Examples ```matlab % Retain only channels 1–64 (remove auxiliary channels) EEG = pop_select(EEG, 'channel', 1:64); % Keep channels by label EEG = pop_select(EEG, 'channel', {'Fp1','Fp2','F3','F4','Fz', 'C3','C4','Cz','P3','P4','Pz'}); % Remove channels by label (exclude EOG and EMG) EEG = pop_select(EEG, 'nochannel', {'EOG1','EOG2','EMG1','EMG2'}); % Keep only epochs 10–50 EEG = pop_select(EEG, 'trial', 10:50); % Keep continuous data from 30 s to 120 s EEG = pop_select(EEG, 'time', [30 120]); % Keep two time windows of continuous data EEG = pop_select(EEG, 'time', [10 60; 70 120]); % Trim each epoch to [-100 500] ms EEG = pop_select(EEG, 'time', [-0.1 0.5]); % in seconds ``` ``` -------------------------------- ### Validate EEG Structure with eeg_checkset Source: https://context7.com/sccn/eeglab/llms.txt Employ `eeg_checkset` to validate and optionally repair the EEG structure. Specific flags like 'data', 'contdata', 'epoch', 'ica', 'chanloc', 'icaconsist', and 'makeur' allow targeted checks or modifications. ```matlab EEG = eeg_checkset(EEG); ``` ```matlab [EEG, changes] = eeg_checkset(EEG, 'data'); ``` ```matlab EEG = eeg_checkset(EEG, 'contdata'); ``` ```matlab EEG = eeg_checkset(EEG, 'epoch'); ``` ```matlab EEG = eeg_checkset(EEG, 'ica'); ``` ```matlab EEG = eeg_checkset(EEG, 'chanloc'); ``` ```matlab [ALLEEG, icaconsist] = eeg_checkset(ALLEEG, 'icaconsist'); disp(icaconsist) ``` ```matlab EEG = eeg_checkset(EEG, 'makeur'); ``` -------------------------------- ### Run ICA Decomposition with pop_runica Source: https://context7.com/sccn/eeglab/llms.txt Performs Independent Component Analysis (ICA) on EEG data using specified algorithms like Infomax, JADE, or FastICA. Populates `EEG.icaweights` and `EEG.icasphere`. Options include 'extended' mode for sub-Gaussian components and channel subsetting. ```matlab % Run Infomax ICA with default settings EEG = pop_runica(EEG, 'icatype', 'runica'); ``` ```matlab % Run with the 'extended' option to capture sub-Gaussian (e.g., line noise) components EEG = pop_runica(EEG, 'icatype', 'runica', 'extended', 1); ``` ```matlab % Run ICA on a subset of channels (skip EOG channels 65, 66) EEG = pop_runica(EEG, 'icatype', 'runica', ... 'chanind', setdiff(1:EEG.nbchan, [65 66])); ``` ```matlab % Run JADE algorithm EEG = pop_runica(EEG, 'icatype', 'jader'); ``` ```matlab % After ICA, inspect weights disp(size(EEG.icaweights)) % [nComponents x nChannels] disp(size(EEG.icasphere)) % [nChannels x nChannels] ``` ```matlab % Compute ICA activations manually icaact = (EEG.icaweights * EEG.icasphere) * reshape(EEG.data, EEG.nbchan, []); ```