


Helper function to create an event triggered matrix from a single
channel of data.
Usage: data=createdatamatpt(data,E,Fs,win)
Inputs:
data (input spike times as a structural array or as a column vector) - required
E (events to use as triggers) - required
E (events to use as triggers) - required
Fs (sampling frequency of data) - required
win (window around triggers to use data matrix -[winl winr]) - required
e.g [-1 1] uses a window starting 1 sec before E and
ending 1 sec after E if E is in secs.
Note that all times can be in arbitrary units. But the units have to be
consistent. So, if E is in secs, win, t have to be in secs, and Fs has to
be Hz. If E is in samples, so are win and t, and Fs=1. In case of spike
times, the units have to be consistent with the units of data as well.
Outputs:
data (transformed data as a structural array)

0001 function data=createdatamatpt(data,E,Fs,win) 0002 % Helper function to create an event triggered matrix from a single 0003 % channel of data. 0004 % Usage: data=createdatamatpt(data,E,Fs,win) 0005 % Inputs: 0006 % data (input spike times as a structural array or as a column vector) - required 0007 % E (events to use as triggers) - required 0008 % E (events to use as triggers) - required 0009 % Fs (sampling frequency of data) - required 0010 % win (window around triggers to use data matrix -[winl winr]) - required 0011 % e.g [-1 1] uses a window starting 1 sec before E and 0012 % ending 1 sec after E if E is in secs. 0013 % Note that all times can be in arbitrary units. But the units have to be 0014 % consistent. So, if E is in secs, win, t have to be in secs, and Fs has to 0015 % be Hz. If E is in samples, so are win and t, and Fs=1. In case of spike 0016 % times, the units have to be consistent with the units of data as well. 0017 % Outputs: 0018 % data (transformed data as a structural array) 0019 % 0020 if nargin < 4; error('Need all input arguments'); end; 0021 if isstruct(data); 0022 fnames=fieldnames(data); 0023 eval(['dtmp=data.' fnames{1} ';']) 0024 else 0025 dtmp=data(:); 0026 end; 0027 N=size(data); 0028 NE=length(E); 0029 winl=win(1); 0030 winr=win(2); 0031 npts=round((winr+winl)*Fs); 0032 data2(1:NE)=struct('times',[]); 0033 for n=1:NE; 0034 indx=find(dtmp > E(n)-winl & dtmp<= E(n)+winr); 0035 if ~isempty(indx); 0036 data2(n).times=dtmp(indx)-E(n)+winl; 0037 else; 0038 data2(n).times=[]; 0039 end; 0040 end; 0041 data=data2;