How to turn a matrix into a vector?
12 views (last 30 days)
Show older comments
I have a matrix with 1000 rows and 1000 columns. And I want to turn it into a vector, that is, putting all the values in a single column and assigning a value (index) to each one. How would I do this? Thank you.
0 Comments
Accepted Answer
Voss
on 20 Dec 2021
I'm not sure what you mean by "assigning a value (index) to each one", but you can use the colon operator to put all the values into a single column:
A = magic(3);
B = A(:);
display(A);
display(B);
As you can see from the output, B is a column vector containing the elements of A in order of: 1st column of A, 2nd column of A, and so on.
0 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!