# createdatamatpt

## PURPOSE

Helper function to create an event triggered matrix from a single

## SYNOPSIS

function data=createdatamatpt(data,E,win)

## DESCRIPTION

     Helper function to create an event triggered matrix from a single
     channel of spike times.
     Usage:  data=createdatamatpt(data,E,win)
     Inputs:
     data   (input spike times as a structural array or as a column vector) - required
     E      (events to use as triggers) - 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 and data are in secs.
     Note that E, win and data must have consistent units
     Outputs:
     data      (event triggered data as a structural array - times are stored
     relative to the E-winl

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- significant-spike-field-coherenceMBL2005
- spike-field-coherenceMBL2005
- coherencysegcpt Multi-taper coherency,cross-spectrum and individual spectra computed by segmenting
- coherencysegpt Multi-taper coherency computed by segmenting two univariate point processes into chunks
- mtspecgramtrigpt Multi-taper event triggered time-frequency spectrum - point process times
- mtspectrumsegpt Multi-taper segmented spectrum for a univariate binned point process
- mtspectrumtrigpt Multi-taper time-frequency spectrum - point process times
- testscript function testscript(pname,direction,movingwin,segave,params,fscorr)

## SOURCE CODE

    0001 function data=createdatamatpt(data,E,win)
    0002 % Helper function to create an event triggered matrix from a single
    0003 % channel of spike times.
    0004 % Usage:  data=createdatamatpt(data,E,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 % win    (window around triggers to use data matrix -[winl winr]) - required
    0009 %          e.g [1 1] uses a window starting 1 sec before E and
    0010 %              ending 1 sec after E if E and data are in secs.
    0011 % Note that E, win and data must have consistent units
    0012 % Outputs:
    0013 % data      (event triggered data as a structural array - times are stored
    0014 % relative to the E-winl
    0015 %
    0016 if nargin < 3; error('Need all input arguments'); end;
    0017 if isstruct(data);
    0018    fnames=fieldnames(data);
    0019    eval(['dtmp=data.' fnames{1} ';'])
    0020 else
    0021    dtmp=data(:);
    0022 end;
    0023 NE=length(E);
    0024 winl=win(1);
    0025 winr=win(2);
    0026 data2(1:NE)=struct('times',[]);
    0027 for n=1:NE,
    0028     indx=find(dtmp > E(n)-winl & dtmp<= E(n)+winr);
    0029     if ~isempty(indx)
    0030        data2(n).times=dtmp(indx)-E(n)+winl;
    0031     else
    0032        data2(n).times=[];
    0033     end
    0034 end
    0035 data=data2;