%% Reshape Matrix to Have Specified Number of Columns
% Reshape a 4-by-4 square matrix into a matrix that has 2 columns. Specify [] for the first dimension to let reshape automatically calculate the appropriate number of rows.

A = magic(4)
B = reshape(A,[],2)

% The result is an 8-by-2 matrix, which maintains the same number of elements as the original matrix. The elements in B also maintain their columnwise order from A.
% Copyright 2012 The MathWorks, Inc.