www.gusucode.com > signal 案例源码程序 matlab代码 > signal/PermuteDimensionsOfAMagicSquareUExample.m

    %% 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.

% Copyright 2015 The MathWorks, Inc.


%%
% 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)