Ticker

6/recent/ticker-posts

How to convert array to matrix in MATLAB?

Question:

How to convert array to matrix in MATLAB?

Answer:

Given any array of numbers can be easily be convetred to matrix by using MATLAB built-in command "reshape".

Example:

Let's create a array of natural numbers from 1 to 16 and store in A matrix

A = 1:16;
A_arr = (reshape(A,[4,4]))

where the second argument of reshape tells the dimension of matrix need to create. In this case, we are interested in 4x4 matrix

OUTPUT

A_arr =

     1     5     9    13
     2     6    10    14
     3     7    11    15
     4     8    12    16

Post a Comment

0 Comments