0001 function y=nt_epochify(x,idx,bounds)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 nt_greetings;
0015
0016 if nargin<3; error('!'); end
0017 if isempty(idx)
0018
0019 if numel(bounds)>1; error('!'); end
0020 idx=1 : bounds : size(x,1)-bounds;
0021 bounds=ceil(bounds);
0022 end
0023 if numel(bounds)==1
0024 bounds=[0 bounds];
0025 end
0026
0027
0028 idx=idx(:);
0029 lowestIdx=-bounds(1);
0030 highestIdx=size(x,1)-bounds(2);
0031 if max(idx)>highestIdx
0032 warning(num2str(numel(idx>highestIdx)));
0033 disp('indices beyond end of data');
0034 idx=idx(idx<=highestIdx);
0035 end
0036 if min(idx)<lowestIdx
0037 warning(num2str(numel(idx<lowestIdx)));
0038 disp('indices beyond end of data');
0039 idx=idx(idx>=lowestIdx);
0040 end
0041
0042
0043 nsamples=bounds(2)-bounds(1)+1;
0044 if idx == round(idx)
0045
0046 y=zeros(nsamples, size(x,2), numel(idx));
0047 for k=1:numel(idx);
0048 y(:,:,k)=x(tidx(k)+(bounds(1):bounds(2)),:);
0049 end
0050 else
0051
0052 warning('noninteger indices, using interpolation');
0053 sidx=repmat(idx, [1,nsamples]) + repmat((1:nsamples),[numel(idx,1),1]);
0054 sidx=sidx(:);
0055 yy=interp1(1:size(x,1),x,sidx+bounds(1));
0056 y=nt_fold(yy,bounds(2)-bounds(1)+1);
0057 end
0058