Skip to content

Commit

Permalink
handle empty events and issue with different number of session per su…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
arnodelorme committed May 25, 2022
1 parent 24b42f4 commit 20f89e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bids_export.m
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,14 @@ function bids_export(files, varargin)
% convert all runs and session to cell array of string
if ~iscell(files(iSubj).run) files(iSubj).run = mattocell(files(iSubj).run); end
if ~iscell(files(iSubj).session) files(iSubj).session = mattocell(files(iSubj).session); end
clear strs;
for iVal = 1:length(files(iSubj).task)
files(iSubj).run{ iVal} = num2str(files(iSubj).run{ iVal});
files(iSubj).session{iVal} = num2str(files(iSubj).session{iVal});
strs{iVal} = strcat(files(iSubj).task{iVal}, files(iSubj).run{iVal}, files(iSubj).session{iVal});
end
if length(strs) ~= length(unique(strs))
error(sprintf('Subject %s does not have unique task, session and runs for each file', iSubj));
error(sprintf('Subject %d does not have unique task, session and runs for each file', iSubj));
end
end
end
Expand Down
11 changes: 6 additions & 5 deletions pop_eventinfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
end

% perform check to make sure EEG.event is consistent across EEG
if isempty(EEG(1).event)
errordlg2('EEG.event is empty for first dataset');
return
end
try
eventFields = fieldnames([EEG.event]);
allEvents = [EEG.event];
if ~isempty(allEvents)
eventFields = fieldnames(allEvents);
else
return; % empty
end
catch ME
if (strcmp(ME.identifier, 'MATLAB:catenate:structFieldBad'))
numFields = cellfun(@(x) numel(fieldnames(x)), {EEG.event});
Expand Down

0 comments on commit 20f89e7

Please sign in to comment.