How to convert a matrix to a vector on Matlab and Octave
To convert a matrix into a vector in Matlab and Octave type M (:)
This command takes all elements in the rows and columns of the matrix M as a single column vector.
Create a 2x2 matrix
>> M = [ 1 2 ; 3 4 ]
To transform matrix M into a column vector type M (:)
The result is a column vector with 4 elements.
Alternatively, type M(:)' to get a row vector
ans = 1 3 2 4
The final result is a row vector with four elements
Report us an error or send a suggestion to improve this page