Home > chronux_0.5 > 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); C=length(data);
0024 elseif min(size(data))~=1; error('Can only accept single column data unless it is a struct array'); 
0025 else C=1; end;
0026 %fnames=fieldnames(data);
0027 for c=1:C,
0028     if isstruct(data)
0029        fnames=fieldnames(data);
0030        eval(['dtmp=data(c).' fnames{1} ';'])
0031     else
0032        dtmp=data(:);
0033     end
0034 %     eval(['dtmp=data(c).' fnames{1} ';' ])
0035     sp=dtmp(dtmp>=t(1) & dtmp<t(2));
0036     if offset==1; d2(c).times=sp-t(1); 
0037     else d2(c).times=sp;end
0038 end;
0039 data=d2;

Generated on Tue 16-Aug-2005 21:33:45 by m2html © 2003