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

    %% Reshape Matrix to Have Specified Number of Columns  

%% 
% Reshape a 6-by-6 magic square matrix into a matrix that has only 3 columns.
% Specify |[]| for the first dimension size to let |reshape| automatically
% calculate the appropriate number of rows. 
A = magic(6);
B = reshape(A,[],3) 

%%
% The result is a 12-by-3 matrix, which maintains the same number of elements
% (36) as the original 6-by-6 matrix. The elements in |B| also maintain
% their columnwise order from |A|.