function [y,varargout]=tsraster(r,t,varargin) % [y,x]=tsraster(r,t,['pre',2,'post',2,'bin_size',0.01) % Computes the cross-correlation of 2 point processes, r(ef) and t(arget) % using a time w(indow) in sec. % either provide one window input and it will use +/- w or provide pre and % post. % r and t should be vectors of timestamps in sec % % bins are LEFT-ALIGNED. Meaning the bin at x==0 are the spikes from 0 to % bin_size % % note: instead of a list of option one can pass options as a struct: % opt.pre=2; opt.post=4; ..... %% SETUP post=2; pre=2; bin_size=0.01; utils.overridedefaults(who, varargin); % if either are empty return empty if isempty(r) y=[]; varargout{1}=[]; return end if isempty(t) t=r(1)-pre-bin_size-1; end % if w is zero or negative, complain if (post+pre)<=0 y=[]; error('window is negative in size') return end % make sure r and t are column vectors. r=r(:); t=t(:); %% The meat of the code. Really brain dead simple. y=zeros(length(r),length(-pre:bin_size:post)-1); for i=1:length(r) % old slow way % cc=t-r(i); % cc=cc((cc>-pre)&(cc