tags:

views:

187

answers:

2

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]

I would be very thankful if anyone suggested any simple method or perhaps points out a function if it already exists that could generate matrix B from original matrix A.

A: 

Try this: B = A ( : ), or try the reshape function.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/reshape.html

Andreas Brinck
`B = A(:);` won't work in this case, since it will put all of the columns into one column vector.
gnovice
You can simply transpose the matrix an vector (with ' if I remember correctly)
Andreas Brinck
don't use `'` if you have complex numbers as it flips the signs of the complex component; use `B = permute([2 1],A(:))`
KitsuneYMG
+1  A: 

You can use the function RESHAPE:

B = reshape(A.',1,[]);
gnovice
Be careful with the ' operator here, as if your data is complex, this will give you a conjugate transpose. Better is to use .' in this operation.
woodchips
@woodchips: Good point. Updated.
gnovice

related questions