Alex Rivera | Logout

the easiest way to convert matrix to one row vector

Asked 2010-04-28T15:24:50.147
20

Possible Duplicate:
How do you concatenate the rows of a matrix into a vector in MATLAB?

Hi,

Does anyone know what is the best way to create one row matrix (vector) from M x N matrix by putting all rows, from 1 to M, of the original matrix into first row of new matrix the following way:

A = [row1; row2; ...; rowM]
B = [row1, row2, ..., rowM]

Example:

A = [1 1 0 0; 0 1 0 1]
B = [1 1 0 0 0 1 0 1]

Is there a simple method or perhaps a built-in function that could generate matrix B from A?

Edit
Report

1 Answer

25

You can use the function RESHAPE:

B = reshape(A.',1,[]);
answered 2010-04-28T15:47:35.290

Your Answer