Talk:Spike2

From SCCN
Jump to: navigation, search

Below is a script in Matlab that imports Skipe2 files to EEGLAB. It might have to be adapted to your specific need (sampling rate), event channels etc... but it is a start. Feel free to edit/change the script and distribute it as an EEGLAB plugin - Arnaud Delorme, Nov 2013

eeglab;
 
[filename, pathname] = uigetfile('*.mat', 'Import Skipe 2 file exported to Matlab');
tmp = load('-mat', fullfile(pathname, filename)); % look at this structure, this is your data from Spike2
srate= 1000; % change the sampling rate
 
% import data (only import data channels)
data = [];
fieldNames = fieldnames(tmp);
for chan = 1:length(fieldNames)
    if isfield(tmp.(fieldNames{chan}), 'values')
        tmpdata = tmp.(fieldNames{chan}).values';
        if length(tmpdata) < size(data,2)
            tmpdata(end+1:size(data,2)) = 0;
        end;
        if isempty(data), data = tmpdata;
        else data(end+1,:) = tmpdata(1:size(data,2));
        end;
    end;
end;
 
% import events from last channel
% this is highly tailored to the task that was used
% which contained event types in the first column of the
% codes fiels. You might have to edit this part
EEG = pop_importdata('data', data, 'srate', srate);
events = tmp.(fieldNames{end});
for iEvent= 1:length(events.times)
    EEG.event(end+1).type  = events.codes(iEvent,1);
    EEG.event(end).latency = events.times(iEvent)*srate+1;
end;
EEG = eeg_checkset(EEG, 'eventconsistency');
 
% store EEG dataset in EEGLAB and redraw the EEGLAB interface
[ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG);
eeglab redraw