Clear Filters
Clear Filters

how to format vector as matrix?

1 view (last 30 days)
Berbia
Berbia on 1 Dec 2012
I have a long row vector say,v=[1 2 3 ... 100]. I'm in need to convert it into a matrix m=[1 2 3 4 5;6 7 8 9 10; ..... ;96 97 98 99 100] i.e),for each row 5 elements...Is it possible in matlab? if so how???

Accepted Answer

Walter Roberson
Walter Roberson on 1 Dec 2012
m = reshape(v, 5, []) .' ;
Notice this first creates columns of 5 and then transposes so they become rows, rather than creating rows of 5 directly. This has to do with the order that reshape() takes elements to be reshaped.

More Answers (0)

Categories

Find more on Matrices and Arrays 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!