Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the easiest way to convert matrix to one row vector [duplicate]

Tags:

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?

like image 694
Niko Gamulin Avatar asked Apr 28 '10 15:04

Niko Gamulin


People also ask

How do you turn a matrix into a row vector?

Conversion of a Matrix into a Row Vector. This conversion can be done using reshape() function along with the Transpose operation. This reshape() function is used to reshape the specified matrix using the given size vector.

How do you repeat a row vector in MATLAB?

B = repmat( A , r ) specifies the repetition scheme with row vector r . For example, repmat(A,[2 3]) returns the same result as repmat(A,2,3) .

How do you change a column vector to a row vector in MATLAB?

Column vectors are created using square brackets [ ], with semicolons or newlines to separate elements. A row vector may be converted into a column vector (and vice versa) using the transpose operator '.


1 Answers

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

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

like image 113
Andreas Brinck Avatar answered Sep 30 '22 08:09

Andreas Brinck