Preparation
Create a matrix using the following code:
A = [1:6;7:12];
Syntax (I)
B = reshape(A,sz)
copies the elements in matrix A
to a new matrix B
of size sz
. sz
is normally a row vector and must contain at least two elements.
% A as a 3by4 matrix
resultExample1 = reshape(A,[3,4]);
% A as a 3by2by2 matrix
resultExample2 = reshape(A,[3,2,2]);
Syntax (II)
B = reshape(A,sz1,…,szN)
copies the elements in matrix A
to a new matrix B
of size determined by the commaseparated list sz1,…,szN
.
If a value in the list is []
, MATLAB calculates the size of the corresponding dimension automatically. The list must have at least two elements and only one can be []
.
% A as a 6by2 matrix
resultExample3 = reshape(A,6,2);
% A as a 4by3 matrix
resultExample4 = reshape(A,[],3);
Note: In both syntaxes, the output size must guarantee that the number of elements in A
and B
is equal.
Further reading
I recommend the following books to learn more on matrix reshaping in MATLAB.

MATLAB: A Practical Introduction to Programming and Problem Solving (4th Edition)
This book was the winner of a 2017 Textbook Excellence Award. The second chapter explains how to perform a wide list of operations on matrices, including matrix reshaping.

MATLAB for Engineers (5th Edition)
This excellent book is especially oriented to engineers and scientists who want to learn MATLAB programming. Matrix manipulation is explained in the fourth chapter.
I also recommend the following page in the MATLAB help documentation, and the other tutorials in this series.
doc reshape;
Exercise
Create a row vector using the following code:
X = 1:16;
Reshape X
so it has:
 Two rows and eight columns
 Eight rows and two columns
 Four rows and four columns
Source code
I hope you have learned how to reshape a matrix in MATLAB. The source code developed in this tutorial is available at this page.