badsamples.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function res = badsamples(this, chanind, sampind, trialind)
  2. % Returns an array of 0/1 marking bad data based on artefact events and bad flags
  3. % FORMAT res = badsamples(this, chanind, sampind, trialind)
  4. % _______________________________________________________________________
  5. % Copyright (C) 2013 Wellcome Trust Centre for Neuroimaging
  6. % Vladimir Litvak
  7. % $Id: badsamples.m 7199 2017-11-01 16:42:12Z vladimir $
  8. if ischar(chanind) && isequal(chanind, ':')
  9. chanind = 1:nchannels(this);
  10. end
  11. if ischar(sampind) && isequal(sampind, ':')
  12. sampind = 1:nsamples(this);
  13. end
  14. if ischar(trialind) && isequal(trialind, ':')
  15. trialind = 1:ntrials(this);
  16. end
  17. if ~isequal(type(this), 'continuous') && ~any(trialonset(this))
  18. error('Trial onset information is not available. Cannot map artefact events to samples.');
  19. end
  20. res = false(length(chanind), nsamples(this), length(trialind));
  21. for i = 1:length(trialind)
  22. ev = events(this, trialind(i));
  23. if iscell(ev)
  24. ev = ev{1};
  25. end
  26. if ~isempty(ev)
  27. ev = ev(intersect(strmatch('artefact', {ev.type}),...
  28. find(cellfun(@ischar, {ev.value}))));
  29. for k = 1:numel(ev)
  30. [dum, chan] = intersect(chanind, selectchannels(this, ev(k).value));
  31. samples = find((trialonset(this, trialind(i))+time(this))>=ev(k).time & ...
  32. (trialonset(this, trialind(i))+time(this))<=(ev(k).time+ev(k).duration));
  33. res(chan, samples, i) = true;
  34. end
  35. end
  36. end
  37. res = res(:, sampind, :);
  38. res(badchannels(this, chanind), :, :) = true;
  39. res(:, :, badtrials(this, trialind)) = true;