next up previous contents
Next: EYE Identity Matrix Up: Array Generation and Manipulations Previous: REPMAT Array Replication Function   Contents

Subsections

CIRCSHIFT Circularly Shift an Array

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 = 
  <int32>  - size: [4 5]
 
Columns 1 to 5
             8              6              9              9              4  
             9              0              9              4              9  
             1              2              1              8              7  
             9              5              9              1              9  
--> circshift(x,[1,0])
ans = 
  <int32>  - size: [4 5]
 
Columns 1 to 5
             9              5              9              1              9  
             8              6              9              9              4  
             9              0              9              4              9  
             1              2              1              8              7  
--> circshift(x,[0,-1])
ans = 
  <int32>  - size: [4 5]
 
Columns 1 to 5
             6              9              9              4              8  
             0              9              4              9              9  
             2              1              8              7              1  
             5              9              1              9              9  
--> circshift(x,[2,2])
ans = 
  <int32>  - size: [4 5]
 
Columns 1 to 5
             8              7              1              2              1  
             1              9              9              5              9  
             9              4              8              6              9  
             4              9              9              0              9  
--> x = int32(rand(4,5,3)*10)
x = 
  <int32>  - size: [4 5 3]
(:,:,1) = 
 
Columns 1 to 5
             6              6              6              2              6  
             0              7              1              0              3  
             8              7              7              0              9  
             9              3              0              8              0  
(:,:,2) = 
 
Columns 1 to 5
             4              1              7              6              9  
             3              4              7              1              3  
             7              4              2              1              5  
             7              6              6              4              2  
(:,:,3) = 
 
Columns 1 to 5
             7              8              1              8              1  
             2              9              2              2              2  
             5              5              8              9              6  
             6              1              2              3              4  
--> circshift(x,[1,0,0])
ans = 
  <int32>  - size: [4 5 3]
(:,:,1) = 
 
Columns 1 to 5
             9              3              0              8              0  
             6              6              6              2              6  
             0              7              1              0              3  
             8              7              7              0              9  
(:,:,2) = 
 
Columns 1 to 5
             7              6              6              4              2  
             4              1              7              6              9  
             3              4              7              1              3  
             7              4              2              1              5  
(:,:,3) = 
 
Columns 1 to 5
             6              1              2              3              4  
             7              8              1              8              1  
             2              9              2              2              2  
             5              5              8              9              6  
--> circshift(x,[0,-1,0])
ans = 
  <int32>  - size: [4 5 3]
(:,:,1) = 
 
Columns 1 to 5
             6              6              2              6              6  
             7              1              0              3              0  
             7              7              0              9              8  
             3              0              8              0              9  
(:,:,2) = 
 
Columns 1 to 5
             1              7              6              9              4  
             4              7              1              3              3  
             4              2              1              5              7  
             6              6              4              2              7  
(:,:,3) = 
 
Columns 1 to 5
             8              1              8              1              7  
             9              2              2              2              2  
             5              8              9              6              5  
             1              2              3              4              6  
--> circshift(x,[0,0,-1])
ans = 
  <int32>  - size: [4 5 3]
(:,:,1) = 
 
Columns 1 to 5
             4              1              7              6              9  
             3              4              7              1              3  
             7              4              2              1              5  
             7              6              6              4              2  
(:,:,2) = 
 
Columns 1 to 5
             7              8              1              8              1  
             2              9              2              2              2  
             5              5              8              9              6  
             6              1              2              3              4  
(:,:,3) = 
 
Columns 1 to 5
             6              6              6              2              6  
             0              7              1              0              3  
             8              7              7              0              9  
             9              3              0              8              0  
--> circshift(x,[2,-3,1])
ans = 
  <int32>  - size: [4 5 3]
(:,:,1) = 
 
Columns 1 to 5
             9              6              5              5              8  
             3              4              6              1              2  
             8              1              7              8              1  
             2              2              2              9              2  
(:,:,2) = 
 
Columns 1 to 5
             0              9              8              7              7  
             8              0              9              3              0  
             2              6              6              6              6  
             0              3              0              7              1  
(:,:,3) = 
 
Columns 1 to 5
             1              5              7              4              2  
             4              2              7              6              6  
             6              9              4              1              7  
             1              3              3              4              7


Samit K. Basu 2005-03-16