events.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. function res = events(this, varargin)
  2. % Method for getting/setting events per trial
  3. % FORMAT res = events(this, ind, event)
  4. % ind = indices of trials
  5. % _______________________________________________________________________
  6. % Copyright (C) 2008-2013 Wellcome Trust Centre for Neuroimaging
  7. % Vladimir Litvak
  8. % $Id: events.m 5613 2013-08-15 11:56:07Z vladimir $
  9. if nargin == 2
  10. res = getset(this, 'trials', 'events', varargin{:});
  11. elseif nargin == 3 && ischar(varargin{2})
  12. ev = getset(this, 'trials', 'events', varargin{1});
  13. onsets = trialonset(this, varargin{1});
  14. if ~iscell(ev)
  15. ev = {ev};
  16. strct = 1;
  17. else
  18. strct = 0;
  19. end
  20. for j = 1:numel(ev)
  21. event = ev{j};
  22. if ~isempty(event)
  23. for i = 1:numel(event)
  24. event(i).time = event(i).time - onsets(j);
  25. if isequal(varargin{2}, 'samples')
  26. if onsets(j) == 0
  27. event(i).sample = event(i).time*this.Fsample;
  28. else
  29. event(i).sample = event(i).time*this.Fsample+1;
  30. end
  31. event(i).duration = ceil(event(i).duration*this.Fsample);
  32. event(i).sample = max(round(event(i).sample), 1);
  33. end
  34. end
  35. if isequal(varargin{2}, 'samples')
  36. event = rmfield(event, 'time');
  37. end
  38. end
  39. ev{j} = event;
  40. end
  41. if strct
  42. res = ev{1};
  43. else
  44. res = ev;
  45. end
  46. else
  47. res = getset(this, 'trials', 'events', varargin{:});
  48. end