how to use the function get_epochs to extract all the epochs from the raw eeg recording in matlab

Assuming you have loaded your EEG data into a raw variable (using functions such as ft_preprocessing or fieldtripread), here is an example code that extracts all the epochs using the ft_redefinetrial function:

main.m
cfg = [];
cfg.trialdef.eventtype  = 'trigger'; % replace with your event type
cfg.trialdef.eventvalue = 1:10; % replace with your event values of interest
cfg.trialdef.prestim    = 0.5; % duration of pre-stimulus interval (in seconds)
cfg.trialdef.poststim   = 1; % duration of post-stimulus interval (in seconds)
cfg = ft_definetrial(cfg, raw);

% redefine trial based on cfg
epochs = ft_redefinetrial(cfg, raw);
414 chars
10 lines

This code defines trial epochs based on a trigger event type and a range of trigger values (eventvalue). The prestim and poststim parameters specify the length of time (in seconds) to extract before and after the trigger event.

The output variable epochs will contain all the extracted epochs as separate trials, which you can then use for further analysis.

Note: Before running this code, make sure you have added FieldTrip to your Matlab path by running ft_defaults or adding the FieldTrip folder to your Matlab path manually.

related categories

gistlibby LogSnag