how to convert a matrix into a vector

5 vues (au cours des 30 derniers jours)
Tanner D Whatley
Tanner D Whatley le 18 Mar 2021
Hello all!
I have this matrix that is a size n x N and i would like to convert this matrix into a a vector of n*N x 1.
N = 401 and n = 5
so this is saying that every column has 5 dta points and I would like to have a column vector of the first column in the original matrix being the first set of rows in the new vector, the next column of the matrix be the next set of rows in vector etc.
Any help on automating this so I don't have to hard code a new column vector would be much appriciated!

Réponse acceptée

Cris LaPierre
Cris LaPierre le 18 Mar 2021
Use the colon
a=rand(2,5)
a = 2×5
0.5636 0.5594 0.7487 0.8379 0.7064 0.0096 0.3643 0.6275 0.2889 0.1544
A = a(:)
A = 10×1
0.5636 0.0096 0.5594 0.3643 0.7487 0.6275 0.8379 0.2889 0.7064 0.1544
  1 commentaire
Tanner D Whatley
Tanner D Whatley le 18 Mar 2021
thank you that works great!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by