how to convert a matrix into one single column vector

조회 수: 119 (최근 30일)
Omar
Omar 2016년 10월 25일
댓글: Swati Sarangi 2021년 1월 4일
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
Pankaj Dey
Pankaj Dey 2018년 11월 23일
Thanks James
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