Authored by Anthony Boyer

New detects c3,p3,c4,p4 duplicates and excludes the scalp channels.

... ... @@ -145,20 +145,9 @@ for i0 = 1:size(t,1)
(any(Sensors.label{i1} == '''') && strcmp(strrep(upper(Sensors.label{i1}), '''', 'p'), Name{iChanPos}))
disp(['ImaGIN> WARNING: Channel name conflict: ' Sensors.label{i1} ' matched with ' Name{iChanPos} ', ' chMatchLog{iPrevious,1} ' discarded.']);
chMatchLog(iPrevious,:) = [];
% If both labels are the same regardless of the case, pick the one with uppercase (intra-recording).
% If both labels are the same regardless of the case, raises an error.
elseif strcmpi(chMatchLog{iPrevious,1},Sensors.label{i1})
uppercase_label = find([sum(isstrprop(chMatchLog{iPrevious,1},'upper'))>0 sum(isstrprop(Sensors.label{i1},'upper'))>0]);
if numel(uppercase_label) == 1
disp(['ImaGIN> WARNING: Channel name conflict: ' Sensors.label{i1} ' matched with ' Name{iChanPos} ', ' chMatchLog{iPrevious,1} ' discarded.']);
% Rename the scalp electrode and remove the coordinates
scalp_idx = find(strcmp(SpmMat.D.sensors.eeg.label,chMatchLog{iPrevious,1}));
Sensors.elecpos(scalp_idx,:) = nan(1,3);
Sensors.chanpos(scalp_idx,:) = nan(1,3);
Sensors.label{scalp_idx} = ['SCALP' Sensors.label{scalp_idx}];
chMatchLog(iPrevious,:) = [];
else
error(['Duplicated label found: ' Sensors.label{i1}]);
end
error(['Duplicated label found: ' Sensors.label{i1}]);
else
disp(['ImaGIN> WARNING: Channel name conflict: ' chMatchLog{iPrevious,1} ' matched with ' Name{iChanPos} ', ' Sensors.label{i1} ' discarded.']);
iChanPos = [];
... ...
... ... @@ -178,7 +178,11 @@ for i = 1:length(AllNames)
continue;
elseif isSEEG && ismember(lower(AllNames{i}), {'o1','o2'}) && ~any(ismember({'o3','o4','o4','o5','o6','o7','o8','o9','o10','o11','o12','o13','o14','o15','o16','o17','o18'}, lower(AllNames)))
continue;
% Otherwise: accept
elseif isSEEG && ismember(lower(AllNames{i}), {'c3','p3','c4','p4'}) && numel(find(ismember(lower(AllNames),lower(AllNames(i)))))>1 && is_scalp(i,AllNames,AllTags)
disp(['Excluding: ' AllNames{i} ' -> detected as a SCALP channel.']);
continue; % if c3 exists more than once AND is NOT preceded by c2 OR c5, is considered a scalp channel and will not be selected. Same for p3, c4, p4.
% Otherwise: accept
else
iSel(end+1) = i;
end
... ... @@ -201,3 +205,21 @@ iSel = [iSel(iOrderSel), iEcg];
% Return lists of selected channels and electrode names
chTags = AllTags;
chInd = AllInd;
end
function scalp_bool = is_scalp(i,AllNames,AllTags)
%% For a given (duplicated) label X, checks if X2 OR X5 exist. If not, is considered as a scalp label.
duplicate_label_idxs = find(ismember(lower(AllNames),lower(AllNames(i)))); % List of duplicates
current_duplicate_idx = find(duplicate_label_idxs == i); % Duplicate being evaluated (infers i is always a duplicate index when this function is called)
if current_duplicate_idx == numel(duplicate_label_idxs) % Last duplicate in the duplicate_label_idxs list
upper_range = i+1:numel(AllNames);
else
upper_range = i+1:duplicate_label_idxs(current_duplicate_idx+1);
end
if current_duplicate_idx == 1 % First duplicate in the duplicate_label_idxs list
lower_range = 1:i-1;
else
lower_range = duplicate_label_idxs(current_duplicate_idx-1):i-1;
end
scalp_bool = ~(ismember(lower([AllTags{i} '2']),lower(AllNames(lower_range))) || ismember(lower([AllTags{i} '5']),lower(AllNames(upper_range))));
end
\ No newline at end of file
... ...