Change row vector to column vector

How can I change this into a column, at the moment all 750 entries are on one row?

p = normal(1:750)-1;

I have tried:

columns = 1;
p = normal(1:750)-1;
p = p(1:columns);

I have also tried:

rows = 1000;
p = normal(1:750)-1;
p = p(1:rows)';


I would imagine you could just transpose:

p = (normal(1:750)-1)'

It is common practice in MATLAB to use the colon operator : for converting anything into a column vector. Without knowing or caring if normal is a row vector or a column vector, you can force p to be a column vector, like so:

p = p(:);

After this, p is guaranteed to be a column vector.


p = p(:);

is indeed the best approach, because it will reliably create column vector.

Beware of the use of the ' operator to do transpose. I have seen it fail dramatically many times. The matlab operator for non-conjugate transpose is actually .' so you would do:

p = p.'

if you want to do transpose without taking the complex conjugate.

Need Your Help

Solutions for INSERT OR UPDATE on SQL Server

sql sql-server database insert upsert

Assume a table structure of MyTable(KEY, datafield1, datafield2...).

Why does Rails create a controller for every request?

ruby-on-rails controller

From my previous question I understood that Rails creates a controller instance for every request.