%% Shift Matrix Elements
% Create a numeric array with a cluster of ones in the top left.

A = [1 1 0 0; 1 1 0 0; 0 0 0 0; 0 0 0 0]

%
% Use circshift to shift each row of A one position to the right.

Y = circshift(A,1,2)

%
% Shift the elements of A by one position in each dimension. The cluster of ones is now in the center of the matrix.

Y = circshift(A,[1 1])

%
% To move the cluster back to its original position, use circshift on Y with negative shift values. The matrix X is equivalent to A.

X = circshift(Y,[-1 -1])

% Copyright 2012 The MathWorks, Inc.