Authored by Anthony Boyer

Fix when 2 consecutive stims are very close (<1s): out of bound stim artefacts w…

…ere wrongfully added to the crop's events.
@@ -140,10 +140,16 @@ function D=ImaGIN_EventsAdd_Subfunction(Filename,NewName,Timing,NeventNew) @@ -140,10 +140,16 @@ function D=ImaGIN_EventsAdd_Subfunction(Filename,NewName,Timing,NeventNew)
140 n=NeventOld; 140 n=NeventOld;
141 for i0=1:NeventNew 141 for i0=1:NeventNew
142 for i1=1:length(Timing{i0}) 142 for i1=1:length(Timing{i0})
143 - n=n+1;  
144 - evt(n).type = NewName{i0};  
145 - evt(n).time = Timing{i0}(i1);  
146 - evt(n).value = NeventOld+i0; 143 + % When 2 stimulations are particularly close to each other
  144 + % ImaGIN_StimDetect may detect a few stimulation artefacts (the "Timing" variable) which are
  145 + % out of the bounds of the current crop. Those artefacts should not be added as stimulation events.
  146 + % Boyer.A 06/10/2020
  147 + if Timing{i0}(i1) > timeonset(D)
  148 + n=n+1;
  149 + evt(n).type = NewName{i0};
  150 + evt(n).time = Timing{i0}(i1);
  151 + evt(n).value = NeventOld+i0;
  152 + end
147 end 153 end
148 % Add log entry 154 % Add log entry
149 ImaGIN_save_log(fullfile(D), sprintf('Added %dx event %s', length(Timing{i0}), NewName{i0})); 155 ImaGIN_save_log(fullfile(D), sprintf('Added %dx event %s', length(Timing{i0}), NewName{i0}));