reshape

Returns a matrix with the same elements as the input, but with reassigned dimensions.

Syntax

reshape(A, m, n, ...)

R = reshape(A, [m, n, ...])

R = reshape(A, ...,[],...)

Inputs

A
Any valid scalar | vector | matrix.
Type: double | integer | char | string | log
Dimension: scalar | vector | matrix
m, n, ...
Dimensions of the desired matrix.
Type: double | integer
Dimension: scalar
[]
An unspecified dimension.

Outputs

R
The reshaped matrix.

Examples

All dimenions specified

R = reshape([1,5;2,6;3,7;4,8],[2,4])
R = [Matrix] 2 x 4
1  3  5  7
2  4  6  8

One dimension unspecified

R = reshape([1,2,3,4,5,6,7,8],2,[])
R = [Matrix] 2 x 4
1  3  5  7
2  4  6  8