cshift

PURPOSE ^

cshift.m

SYNOPSIS ^

function y = cshift(x, t, dir)

DESCRIPTION ^

 cshift.m

 Circular shift of a row vector.
 Usage : y = cshift(x, t, dir)
 x - input vector
 t - number of spots to shift
 dir - either 'r' or 'l' (default is 'r')

 Written by : Justin Romberg

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % cshift.m
0002 %
0003 % Circular shift of a row vector.
0004 % Usage : y = cshift(x, t, dir)
0005 % x - input vector
0006 % t - number of spots to shift
0007 % dir - either 'r' or 'l' (default is 'r')
0008 %
0009 % Written by : Justin Romberg
0010 
0011 function y = cshift(x, t, dir)
0012 
0013 if (nargin == 2), dir = 'r'; end
0014 
0015 N = size(x,2);
0016 t = mod(t,N);
0017 if (dir == 'r')
0018   y = [x(:,N-t+1:N) x(:,1:N-t)];
0019 else
0020   y = [x(:,1+t:N) x(:,1:t)];
0021 end
0022 
0023 
0024 
0025 %N = length(x);
0026 %t = mod(t, N);
0027 %if (dir == 'r')
0028 %  y = [x(N-t+1:N) x(1:N-t)];
0029 %else
0030 %  y = [x(1+t:N) x(1:t)];
0031 %end

Generated on Mon 10-Jun-2013 23:03:23 by m2html © 2005