CIRCSHIFT Circularly Shift an Array

Section: Array Generation and Manipulations

USAGE

Applies a circular shift along each dimension of a given array. The syntax for its use is
   y = circshift(x,shiftvec)

where x is an n-dimensional array, and shiftvec is a vector of integers, each of which specify how much to shift x along the corresponding dimension.

Example

The following examples show some uses of circshift on N-dimensional arrays.
--> x = int32(rand(4,5)*10)

x = 

 1 3 1 4 0 
 7 2 7 2 4 
 4 0 1 1 8 
 3 6 7 3 5 

--> circshift(x,[1,0])

ans = 

 3 6 7 3 5 
 1 3 1 4 0 
 7 2 7 2 4 
 4 0 1 1 8 

--> circshift(x,[0,-1])

ans = 

 3 1 4 0 1 
 2 7 2 4 7 
 0 1 1 8 4 
 6 7 3 5 3 

--> circshift(x,[2,2])

ans = 

 1 8 4 0 1 
 3 5 3 6 7 
 4 0 1 3 1 
 2 4 7 2 7 

--> x = int32(rand(4,5,3)*10)

x = 

(:,:,1) = 

 6 5 1 7 3 
 7 3 5 5 0 
 3 7 6 6 7 
 3 8 5 8 0 

(:,:,2) = 

 7 2 7 1 8 
 6 8 5 0 2 
 6 9 4 3 6 
 7 4 1 7 6 

(:,:,3) = 

 1 0 1 9 6 
 7 5 5 7 5 
 4 2 6 6 5 
 5 2 4 5 1 

--> circshift(x,[1,0,0])

ans = 

(:,:,1) = 

 3 8 5 8 0 
 6 5 1 7 3 
 7 3 5 5 0 
 3 7 6 6 7 

(:,:,2) = 

 7 4 1 7 6 
 7 2 7 1 8 
 6 8 5 0 2 
 6 9 4 3 6 

(:,:,3) = 

 5 2 4 5 1 
 1 0 1 9 6 
 7 5 5 7 5 
 4 2 6 6 5 

--> circshift(x,[0,-1,0])

ans = 

(:,:,1) = 

 5 1 7 3 6 
 3 5 5 0 7 
 7 6 6 7 3 
 8 5 8 0 3 

(:,:,2) = 

 2 7 1 8 7 
 8 5 0 2 6 
 9 4 3 6 6 
 4 1 7 6 7 

(:,:,3) = 

 0 1 9 6 1 
 5 5 7 5 7 
 2 6 6 5 4 
 2 4 5 1 5 

--> circshift(x,[0,0,-1])

ans = 

(:,:,1) = 

 7 2 7 1 8 
 6 8 5 0 2 
 6 9 4 3 6 
 7 4 1 7 6 

(:,:,2) = 

 1 0 1 9 6 
 7 5 5 7 5 
 4 2 6 6 5 
 5 2 4 5 1 

(:,:,3) = 

 6 5 1 7 3 
 7 3 5 5 0 
 3 7 6 6 7 
 3 8 5 8 0 

--> circshift(x,[2,-3,1])

ans = 

(:,:,1) = 

 6 5 4 2 6 
 5 1 5 2 4 
 9 6 1 0 1 
 7 5 7 5 5 

(:,:,2) = 

 6 7 3 7 6 
 8 0 3 8 5 
 7 3 6 5 1 
 5 0 7 3 5 

(:,:,3) = 

 3 6 6 9 4 
 7 6 7 4 1 
 1 8 7 2 7 
 0 2 6 8 5 

--> 
quit