How to reshape vector into matrix

Home Forums Matlab How to reshape vector into matrix

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  cK 10 years ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #492

    pankaj kumar
    Participant

    I have attached one word doc and like to learn to convert a given vector pr into matrix in particular fashion.

    Attachments:
    You must be logged in to view attached files.
    #494

    cK
    Keymaster

    You can use reshape() or vec2mat(). The latter one is avbl in communications toolbox.

    x = 1:12;
    m = reshape(x,3,4)
    m =
         1     4     7    10
         2     5     8    11
         3     6     9    12

    Reshape fills matrix’s columns first (vec2mat does rows first). If rows need to be filled, the matrix can later be transposed. To reshape a vector into a matrix of size MxN using reshape(), the vector must have exactly M*N elements (vec2mat doesn’t need that).

    • This reply was modified 10 years ago by  cK.
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.