how to convert a matrix into one single column vector

61 次查看(过去 30 天)
I am trying to convert a matrix into one column vector. For example, if I have A=[1 2 3;3 4 5;0 2 5] and I want to transpose all the rows and combine them to get one single column vector like B=[1;2;3;3;4;5;0;2;5]. Anyone has an idea on how to do it, please help me.

采纳的回答

James Tursa
James Tursa 2016-10-25
B = reshape(A',[],1);
  3 个评论
Swati Sarangi
Swati Sarangi 2021-1-4
@James, Thanks for this code. It's working perfectly.
The above traverses the matrix column wise and converts it into a 1D vector. Little extension to this problem, when this traversal is row wise in the matrix and then it is converterd to the vector. What should be the code for it?

请先登录,再进行评论。

更多回答(1 个)

Souarv De
Souarv De 2019-9-18
Thanks

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by