0001 function [z,zz]=nt_multishift(x,shifts,pad)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 if nargin<2; error('!'); end
0017 if nargin<3; pad=0; end
0018
0019 if nargout==2
0020
0021 z=nt_multishift(x,shifts,pad);
0022 zz=reshape(z,[size(z,1),numel(shifts),size(x,2),size(x,3)]);
0023 return
0024 end
0025
0026 if iscell(x)
0027 for iCell=1:length(x);
0028 z{iCell}=nt_multishift(x{iCell},shifts);
0029 end
0030 return;
0031 end
0032
0033 if size(x,1)<max(shifts); error('shifts should be no larger than nrows'); end
0034 if min(shifts)<0; error('shifts should be nonnegative'); end
0035 shifts=shifts(:)';
0036 nshifts=numel(shifts);
0037 if nshifts==1 && shifts(1)==0;
0038 z=x;
0039 return
0040 end
0041
0042
0043 N=size(x,1)-max(shifts);
0044 shiftarray=nt_vecadd(nt_vecmult(ones(N,nshifts),shifts),(1:N)');
0045 [m,n,o]=size(x);
0046 z=zeros(N,n*nshifts,o);
0047
0048 for k=1:o
0049 for j=0:n-1
0050 y=x(:,j+1,k);
0051 z(:,j*nshifts+1: j*nshifts+nshifts,k)=y(shiftarray);
0052 end
0053 end
0054
0055 if pad
0056 z(size(x,1),:,:)=0;
0057 end