# how to convert a matrix into one single column vector

112 visualizzazioni (ultimi 30 giorni)
Omar il 25 Ott 2016
Commentato: Swati Sarangi il 4 Gen 2021
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.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

James Tursa il 25 Ott 2016
B = reshape(A',[],1);
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Pankaj Dey il 23 Nov 2018
Thanks James
Swati Sarangi il 4 Gen 2021
@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?

Accedi per commentare.

### Più risposte (1)

Souarv De il 18 Set 2019
Thanks
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by