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