FreeMat
|
Section: Array Generation and Manipulations
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.
The following examples show some uses of circshift
on N-dimensional arrays.
--> x = int32(rand(4,5)*10) x = 4 8 3 2 9 0 8 0 5 3 9 1 5 8 2 4 5 10 3 7 --> circshift(x,[1,0]) ans = 4 5 10 3 7 4 8 3 2 9 0 8 0 5 3 9 1 5 8 2 --> circshift(x,[0,-1]) ans = 8 3 2 9 4 8 0 5 3 0 1 5 8 2 9 5 10 3 7 4 --> circshift(x,[2,2]) ans = 8 2 9 1 5 3 7 4 5 10 2 9 4 8 3 5 3 0 8 0 --> x = int32(rand(4,5,3)*10) x = (:,:,1) = 2 7 7 3 10 2 2 3 7 0 4 8 1 4 0 10 2 7 8 9 (:,:,2) = 5 7 10 9 4 0 3 5 0 4 4 5 1 3 6 9 1 5 1 5 (:,:,3) = 1 5 6 9 2 8 10 6 5 7 6 2 1 6 8 1 9 6 5 3 --> circshift(x,[1,0,0]) ans = (:,:,1) = 10 2 7 8 9 2 7 7 3 10 2 2 3 7 0 4 8 1 4 0 (:,:,2) = 9 1 5 1 5 5 7 10 9 4 0 3 5 0 4 4 5 1 3 6 (:,:,3) = 1 9 6 5 3 1 5 6 9 2 8 10 6 5 7 6 2 1 6 8 --> circshift(x,[0,-1,0]) ans = (:,:,1) = 7 7 3 10 2 2 3 7 0 2 8 1 4 0 4 2 7 8 9 10 (:,:,2) = 7 10 9 4 5 3 5 0 4 0 5 1 3 6 4 1 5 1 5 9 (:,:,3) = 5 6 9 2 1 10 6 5 7 8 2 1 6 8 6 9 6 5 3 1 --> circshift(x,[0,0,-1]) ans = (:,:,1) = 5 7 10 9 4 0 3 5 0 4 4 5 1 3 6 9 1 5 1 5 (:,:,2) = 1 5 6 9 2 8 10 6 5 7 6 2 1 6 8 1 9 6 5 3 (:,:,3) = 2 7 7 3 10 2 2 3 7 0 4 8 1 4 0 10 2 7 8 9 --> circshift(x,[2,-3,1]) ans = (:,:,1) = 6 8 6 2 1 5 3 1 9 6 9 2 1 5 6 5 7 8 10 6 (:,:,2) = 4 0 4 8 1 8 9 10 2 7 3 10 2 7 7 7 0 2 2 3 (:,:,3) = 3 6 4 5 1 1 5 9 1 5 9 4 5 7 10 0 4 0 3 5