createdatamatpt.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. function data=createdatamatpt(data,E,win)
  2. % Helper function to create an event triggered matrix from a single
  3. % channel of spike times.
  4. % Usage: data=createdatamatpt(data,E,win)
  5. % Inputs:
  6. % data (input spike times as a structural array or as a column vector) - required
  7. % E (events to use as triggers) - required
  8. % win (window around triggers to use data matrix -[winl winr]) - required
  9. % e.g [1 1] uses a window starting 1 sec before E and
  10. % ending 1 sec after E if E and data are in secs.
  11. % Note that E, win and data must have consistent units
  12. % Outputs:
  13. % data (event triggered data as a structural array - times are stored
  14. % relative to the E-winl
  15. %
  16. if nargin < 3; error('Need all input arguments'); end;
  17. if isstruct(data);
  18. fnames=fieldnames(data);
  19. eval(['dtmp=data.' fnames{1} ';'])
  20. else
  21. dtmp=data(:);
  22. end;
  23. NE=length(E);
  24. winl=win(1);
  25. winr=win(2);
  26. data2(1:NE)=struct('times',[]);
  27. for n=1:NE,
  28. indx=find(dtmp > E(n)-winl & dtmp<= E(n)+winr);
  29. if ~isempty(indx)
  30. data2(n).times=dtmp(indx)-E(n)+winl;
  31. else
  32. data2(n).times=[];
  33. end
  34. end
  35. data=data2;