Say I have a matrix a = [1 2 3 4 5 6];, how do I reshape it in a row-wise manner for example reshape(a, 2, 3) to yield
1 2 3 4 5 6 rather than the default column-wise result produced by MATLAB of:
1 3 5 2 4 6 I believe this is a trivial task which probably has an inbuilt function to achieve this. I have already implemented a function that does this perfectly... however, is there a shorter, neater and more MATLAB way? Thanks.
function y = reshape2(x, m, n) y = zeros(m, n); ix = 0; for i = 1:m for j = 1:n ix = ix + 1; y(i, j) = x(ix); end end end