%% Permute Dimensions of a Magic Square
% This example shifts x, a 3-by-3 magic square, permuting dimension 2 to the first column. unshiftdata shifts x back to its original shape.
% Create a 3-by-3 magic square.

x = magic(3)

%
% Shift the matrix x to work along the second dimension. The permutation vector, perm, and the number of shifts, nshifts, are returned along with the shifted matrix.

[x,perm,nshifts] = shiftdata(x,2)

%
% Shift the matrix back to its original shape.

y = unshiftdata(x,perm,nshifts)

% Copyright 2015 The MathWorks, Inc.