Home > chronux_code > conditioning > pointtimes > createdatamatpt.m

createdatamatpt

PURPOSE ^

Helper function to create an event triggered matrix from a single

SYNOPSIS ^

function data=createdatamatpt(data,E,Fs,win)

DESCRIPTION ^

 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)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 NE=length(E);
0028 winl=win(1);
0029 winr=win(2);
0030 data2(1:NE)=struct('times',[]);
0031 for n=1:NE,
0032     indx=find(dtmp > E(n)-winl & dtmp<= E(n)+winr);
0033     if ~isempty(indx)
0034        data2(n).times=dtmp(indx)-E(n)+winl;
0035     else
0036        data2(n).times=[];
0037     end
0038 end
0039 data=data2;

Generated on Tue 07-Jun-2005 12:20:32 by m2html © 2003