MATLAB: How to turn a nxm matrix into a single array

manipulationmatrix

hi Matlabers,
say I have a matrix
[1 2 3 4;5 6 7 8;9 10 11 12; 13 14 15 16]
how can I turn this matrix so all the rows are combined into one. one after the other.
result
[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]?
thanks in advance. cheers SN

Best Answer

You can use reshape command:
a= [1 2 3 4;5 6 7 8;9 10 11 12; 13 14 15 16]
b = reshape(a,1,16)
or simply
b = a(:)'
Hope it helps!!!