Skip to content

MATLAB array rows arrangement

An answer to this question on Stack Overflow.

Question

I work with Matlab and I have a transformation result which is a matrix (A) 4x4, for example:

A = [
    1  2  3  4  5  6  7  8
    9 10 11 12 13 14 15 16 
    etc...
    ]

Is there any way to arrange the second row of A after its first row, so that the result would become:

A = [
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 etc... ];

Answer

You can try using vector = A(:) after your first transformation. This will make a column vector, which you can transpose if you want a row vector.

For more control, try the reshape command. For instance, vector = reshape(A,1,[]) should do the same as the above.