clear v = 1:12; % reshape v as 4x3 matrix M = reshape(v, [4,3]); % note: M(:) is a column vector assert(all(M(:) == v.'));