


Extract segements of spike times between t(1) and t(2) Usage: data=extractspdata(data,t) Input: data: structural array of spike times for each channel/trial t : time as a 2d vector [t(1) t(2)] 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)


0001 function data=extractspdata(data,t) 0002 % Extract segements of spike times between t(1) and t(2) 0003 % Usage: data=extractspdata(data,t) 0004 % 0005 % Input: 0006 % data: structural array of spike times for each channel/trial 0007 % t : time as a 2d vector [t(1) t(2)] 0008 % Note that all times can be in arbitrary units. But the units have to be 0009 % consistent. So, if E is in secs, win, t have to be in secs, and Fs has to 0010 % be Hz. If E is in samples, so are win and t, and Fs=1. In case of spike 0011 % times, the units have to be consistent with the units of data as well. 0012 % Output: 0013 % data: spike times between t(1) and t(2) 0014 0015 if isstruct(data); C=length(data); 0016 elseif min(size(data))~=1; error('Can only accept single column data unless it is a struct array'); 0017 else; C=1; end; 0018 %fnames=fieldnames(data); 0019 for c=1:C, 0020 if isstruct(data) 0021 fnames=fieldnames(data); 0022 eval(['dtmp=data(c).' fnames{1} ';']) 0023 else 0024 dtmp=data(:); 0025 end 0026 % eval(['dtmp=data(c).' fnames{1} ';' ]) 0027 sp=dtmp(dtmp>=t(1) & dtmp<t(2)); 0028 d2(c).times=sp; 0029 end; 0030 data=d2;