Home > chronux > spectral_analysis > pointtimes > extractdatapt.m

extractdatapt

PURPOSE ^

Extract segements of spike times between t(1) and t(2)

SYNOPSIS ^

function data=extractdatapt(data,t,offset)

DESCRIPTION ^

 Extract segements of spike times between t(1) and t(2)
 Usage: data=extractdatapt(data,t,offset)

 Input:
 data: structural array of spike times for each channel/trial or a single
       array of spike times
 t   : time as a 2d vector [t(1) t(2)]
 offset: 0/1 - if 1, store the spike times relative to start of window i.e. t(1)
         if 0, don't reset the times. Default 0. 
 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.

 Output:
 data: spike times between t(1) and t(2)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function data=extractdatapt(data,t,offset)
0002 % Extract segements of spike times between t(1) and t(2)
0003 % Usage: data=extractdatapt(data,t,offset)
0004 %
0005 % Input:
0006 % data: structural array of spike times for each channel/trial or a single
0007 %       array of spike times
0008 % t   : time as a 2d vector [t(1) t(2)]
0009 % offset: 0/1 - if 1, store the spike times relative to start of window i.e. t(1)
0010 %         if 0, don't reset the times. Default 0.
0011 % Note that all times can be in arbitrary units. But the units have to be
0012 % consistent. So, if E is in secs, win, t have to be in secs, and Fs has to
0013 % be Hz. If E is in samples, so are win and t, and Fs=1. In case of spike
0014 % times, the units have to be consistent with the units of data as well.
0015 %
0016 % Output:
0017 % data: spike times between t(1) and t(2)
0018 if nargin < 2; error('Need data and times'); end;
0019 if t(1) < 0 || t(2)<=t(1);
0020     error('times cannot be negative and t(2) has to greater than t(1)');
0021 end;
0022 if nargin < 3 || isempty(offset); offset=0; end;
0023 if isstruct(data); 
0024     C=length(data);
0025 elseif min(size(data))~=1; 
0026     error('Can only accept single vector data unless it is a struct array'); 
0027 else
0028     C=1;
0029     data=change_row_to_column(data);
0030 end;
0031 %fnames=fieldnames(data);
0032 d2(1:C)=struct('times',[]);
0033 for c=1:C,
0034     if isstruct(data)
0035        fnames=fieldnames(data);
0036        eval(['dtmp=data(c).' fnames{1} ';'])
0037     else
0038        dtmp=data(:);
0039     end
0040 %     eval(['dtmp=data(c).' fnames{1} ';' ])
0041     sp=dtmp(dtmp>=t(1) & dtmp<t(2));
0042     if offset==1; d2(c).times=sp-t(1); 
0043     else d2(c).times=sp;end
0044 end;
0045 data=d2;

Generated on Fri 28-Sep-2012 12:34:30 by m2html © 2005