What is the most simple way to force any vector to be a row vector?
I wish to have some function that transforms column vector to a row vector, and leaves a row vector unchanged. For example:
A= [1 2 3];
RowIt(A)
will output a row vector:
1 2 3
and:
B= [1; 2; 3];
RowIt(B)
will output a row vector:
1 2 3
What is the most simple way to do it?
To get any vector to be a row vector simply first force it to be a column vector, then transpose it:
A = rand(3,1);
B = A(:).'; % (:) forces it to unwrap along columns, .' transposes
A row vector gets unwrapped to a column vector and then transposed to a row vector again, and a column vector gets unwrapped to a column vector (thus doesn't change) and then gets transposed to a row vector.
Note that any N-dimensional matrix will be forced into a row vector this way due to column unwrapping:
A = rand(3,3,3,3);
B = A(:).'; % 81 element row vector
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With