MATLAB Link for Code Composer Studio Development Tools | ![]() ![]() |
Change the shape of an array maintaining the same number of elements
Syntax
Description
reshape(x,m,n)
returns the m
-by-n
array whose elements are taken columnwise from x
. If x
does not have m
*n
elements, reshape
returns an error from the operation.
Generally, reshape(x,siz)
returns an n-dimensional array with the same elements as x
, but reshaped to size(siz)
. Note that prod(siz)
must be the same as prod(size(x))
.
reshape(x,m,n,p...)
returns an n-dimensional array with the same number of elements as x
, but reshaped to have size m
-by-n
-by-p
-by-.... For the reshape operation to work, m
*n
*p*... must equal prod(size(x))
.
reshape(x,[m n p ...])
is the same as the preceding syntax.
reshape(x,...,[],...)
calculates the length of the dimension replaced by []
in the command, so that the product of the dimensions equals prod(size(x))
.For the length calculation to succeed, prod(size(x))
bust be evenly divisible by the product of the known dimensions (all the dimensions exclusive of the unknown dimension). Within the function call, you are allowed to use only one set of square brackets, []
, for one unknown dimension.
![]() | reset | restart | ![]() |