Change row vector to column vector

后端 未结 3 1051
天涯浪人
天涯浪人 2020-12-17 20:28

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:

colum         


        
相关标签:
3条回答
  • 2020-12-17 20:44

    Setting

    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.

    0 讨论(0)
  • 2020-12-17 20:46

    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.

    0 讨论(0)
  • 2020-12-17 21:02

    I would imagine you could just transpose:

    p = (normal(1:750)-1)'
    
    0 讨论(0)
提交回复
热议问题