Hi! The channels.tsv files and electrodes.tsv files of my BIDS data set do not have the same order of rows. I am not sure whether this is a strict requirement in BIDS? In any case, if the order of rows in these files is different, the channel labels in the chanlocs field of the main data structure get scrambled. This happens in the eeg_importchanlocs-function. Here is my suggestion for an adaptation (current implementation commented out):
% chanlocs = [];
% for iChan = 2:size(channelData,1)
% % the fields below are all required
% chanlocs(iChan-1).labels = channelData{iChan,1};
% chanlocs(iChan-1).type = channelData{iChan,2};
% chanlocs(iChan-1).unit = channelData{iChan,3};
% if size(channelData,2) > 3
% chanlocs(iChan-1).status = channelData{iChan,4};
% end
%
% if ~isempty(elecData) && iChan <= size(elecData,1)
% chanlocs(iChan-1).labels = elecData{iChan,1};
% chanlocs(iChan-1).X = elecData{iChan,2};
% chanlocs(iChan-1).Y = elecData{iChan,3};
% chanlocs(iChan-1).Z = elecData{iChan,4};
% end
% end
chanLocsLabels = {EEG.chanlocs.labels};
if(size(channelData,1)-1 ~= length(chanLocsLabels))
error('Mismatch of number of channels in channel.tsv and EEG.data/ EEG.chanlocs.labels structure.')
end
chanlocs = [];
for iChan = 1:(size(channelData,1)-1)
% the fields below are all required
chanlocs(iChan).labels = chanLocsLabels{iChan};
iChanChannelData = find(strcmp(channelData(:,1), chanLocsLabels{iChan}));
chanlocs(iChan).type = channelData{iChanChannelData,2};
chanlocs(iChan).unit = channelData{iChanChannelData,3};
if size(channelData,2) > 3
chanlocs(iChan).status = channelData{iChanChannelData,4};
end
if ~isempty(elecData)
iChanElecData = find(strcmp(elecData(:,1), chanLocsLabels{iChan}));
if(~isempty(iChanElecData))
chanlocs(iChan).X = elecData{iChanElecData,2};
chanlocs(iChan).Y = elecData{iChanElecData,3};
chanlocs(iChan).Z = elecData{iChanElecData,4};
end
end
end
Hi! The channels.tsv files and electrodes.tsv files of my BIDS data set do not have the same order of rows. I am not sure whether this is a strict requirement in BIDS? In any case, if the order of rows in these files is different, the channel labels in the chanlocs field of the main data structure get scrambled. This happens in the eeg_importchanlocs-function. Here is my suggestion for an adaptation (current implementation commented out):