MATLAB Reshape

reshape() command or function reshapes a matrix or vector, after reading this MATLAB Reshape topic, you will know the theory and examples.


Syntax:

reshape(n,a,b)

  • n is a matrix or vector.
  • a is numbers of rows.
  • b is numbers of columns.

Example: To reshape a vector into the matrix.

% create n vector
n=[1,2,3,56]

reshape(n,2,2)

Output:

n =

1  2  3  56


ans =

1   3
2   56

Example: To reshape a matrix into another matrix.

% create the 3x2 matrix
n=[2,3;2,1;5,1]

reshape(n,3,2)

Output:

n =

     2     3
     2     1
     5     1


ans =

     2     5     1
     2     3     1

Published by

Electrical Workbook

We provide tutoring in Electrical Engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *