minmaxsptimes.m 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function [mintime, maxtime]=minmaxsptimes(data)
  2. % Find the minimum and maximum of the spike times in each channel
  3. % Usage: [mintime, maxtime]=minmaxsptimes(data)
  4. % Input:
  5. % data (spike times as a structural array of multiple dimensions e.g. channels; channels x trials;
  6. % can also accept a 1d matrix of spike times)
  7. % Output:
  8. % mintime (minimum of the spike time across channels)
  9. % maxtime (maximum of the spike time across channels)
  10. %
  11. dtmp='';
  12. if isstruct(data)
  13. data=reshape(data,numel(data),1);
  14. C=size(data,1);
  15. fnames=fieldnames(data);
  16. mintime=zeros(1,C); maxtime=zeros(1,C);
  17. for ch=1:C
  18. eval(['dtmp=data(ch).' fnames{1} ';'])
  19. if ~isempty(dtmp)
  20. maxtime(ch)=max(dtmp);
  21. mintime(ch)=min(dtmp);
  22. else
  23. mintime(ch)=NaN;
  24. maxtime(ch)=NaN;
  25. end
  26. end;
  27. maxtime=max(maxtime); % maximum time
  28. mintime=min(mintime); % minimum time
  29. else
  30. dtmp=data;
  31. if ~isempty(dtmp)
  32. maxtime=max(dtmp);
  33. mintime=min(dtmp);
  34. else
  35. mintime=NaN;
  36. maxtime=NaN;
  37. end
  38. end
  39. if mintime < 0
  40. error('Minimum spike time is negative');
  41. end