Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

rasterplot.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. function [yM,xM,h]=rasterplot(r,t,pre,post, varargin)
  2. % [yM,xM,h]=tsraster2(r,t,pre,post, varargin)
  3. % Drows a rasterplot of two point processes, r(ef) and t(arget)
  4. % using a time w(indow) in seconds.
  5. % either provide one window input and it will use +/- w or provide pre and
  6. % post.
  7. % r and t should be vectors of timestamps in seconds
  8. % if would be way faster if i find the smaller of r and t and run through
  9. % r. but i'm not using this for the bootstrap anyway.
  10. %% SETUP
  11. r=r;
  12. t=t;
  13. if nargin<4
  14. post=pre;
  15. end
  16. % if either are empty return empty
  17. if isempty(r)
  18. yM=[]; xM=[];
  19. return
  20. end
  21. if isempty(t)
  22. t=r(1)-pre-1;
  23. end
  24. % if w is zero or negative, complain
  25. if (post+pre)<=0
  26. y=[];
  27. display('window is negative in size')
  28. return
  29. end
  30. % make sure r and t are column vectors.
  31. if isvector(r)
  32. r=r(:);
  33. else
  34. % we might have passed in multipl refs. use the first one
  35. r=r(:,1);
  36. end
  37. t=t(:);
  38. % deal with vararin
  39. % opts.plotthis=1;
  40. % opts.post_mask=+inf;
  41. % opts.pre_mask=-inf;
  42. % opts.events=[]; % this should be a struct with name,
  43. iod = @utils.inputordefault;
  44. plotthis = iod('plotthis',1,varargin);
  45. post_mask = iod('post_mask',+inf,varargin);
  46. pre_mask = iod('pre_mask',-inf,varargin);
  47. events = iod('events',[],varargin);
  48. %parseargs(varargin,opts,{},1);
  49. if isscalar(post_mask)
  50. post_mask=repmat(post_mask, size(r));
  51. end
  52. if isscalar(pre_mask)
  53. pre_mask=repmat(pre_mask, size(r));
  54. end
  55. %% The meat of the code. Really brain dead simple.
  56. spks=zeros(numel(t),2);
  57. spk_ind=1;
  58. for i=1:numel(r)
  59. s=r(i)-pre;
  60. f=r(i)+post;
  61. cc=stats.qbetween(t, s,f)-r(i);
  62. cc=cc(cc>pre_mask(i));
  63. cc=cc(cc<post_mask(i));
  64. if isempty(cc)
  65. cc=nan;
  66. end
  67. s_inc=numel(cc);
  68. %spks=[spks; cc(:), zeros(size(cc(:)))+i];
  69. spks(spk_ind:spk_ind+s_inc-1,:)=[cc, zeros(s_inc,1)+i];
  70. spk_ind=spk_ind+s_inc;
  71. end
  72. spks=spks(1:spk_ind-1,:);
  73. xM=zeros(size(spks,1)*3,1);
  74. yM=xM;
  75. xM(1:3:end)=spks(:,1);
  76. xM(2:3:end)=spks(:,1);
  77. xM(3:3:end)=nan;
  78. yM(1:3:end)=spks(:,2);
  79. yM(2:3:end)=spks(:,2)+.8;
  80. yM(3:3:end)=nan;
  81. if plotthis
  82. h=plot(xM,yM,'k');
  83. end
  84. %% it might be worth returning an unbinned vector