Azzera filtri
Azzera filtri

how to format vector as matrix?

1 visualizzazione (ultimi 30 giorni)
Berbia
Berbia il 1 Dic 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???

Risposta accettata

Walter Roberson
Walter Roberson il 1 Dic 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.

Più risposte (0)

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