0001 function y=nt_epochify(x,tidx,bounds);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if nargin<3; error('!'); end
0015
0016 if numel(bounds)==1; bounds=[0 bounds]; end
0017
0018 if max(tidx)+bounds(2)>size(x,1);
0019 [max(tidx) bounds(2) size(x,1)]
0020 error('epoch stops after end of data');
0021 end
0022 if min(tidx)+bounds(1)<1;
0023 error('epoch starts before beginning of data');
0024 end
0025
0026 y=zeros(bounds(2)-bounds(1)+1, size(x,2), numel(tidx));
0027
0028 if tidx == round(tidx)
0029
0030 for k=1:numel(tidx);
0031 y(:,:,k)=x(tidx(k)+(bounds(1):bounds(2)),:);
0032 end
0033 else
0034
0035 warning('nointeger tidx, using interpolation');
0036 for k=1:numel(tidx);
0037 y(:,:,k)=interp1(1:size(x,1),x,tidx(k)+(bounds(1):bounds(2)));
0038 end
0039 end