Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

reshape

MATLAB reshape function


Description

Reshape matrix or array.

Usage

reshape(A, ...)

Arguments

A

matrix or array containing the original data

...

numeric dimensions for the result

Details

In the first example below, an m-by-n matrix is created whose elements are taken column-wise from A. An error occurs if A does not have m*n elements.

In the second example below, an n-dimensional array with the same elements as A but reshaped to have the size m-by-n-by-p. The product of the specified dimensions must be the same as prod(size(A)).

In the third example below, an n-dimensional array with the same elements as A but reshaped to siz, a vector representing the dimensions of the reshaped array. The quantity prod(siz) must be the same as prod(size(A)).

Value

Returns matrix (or array) of requested dimensions containing the elements of A.

Author(s)

Examples

Xmat.2d <- matrix(1:12, nrow=4, ncol=3)
reshape(Xmat.2d, 6, 2)                   # example 1
reshape(Xmat.2d, c(6, 2))                    # same thing
Xarr.3d <- reshape(Xmat.2d, c(6, 2, 1))  # example 2
reshape(Xmat.2d, size(Xarr.3d))          # example 3

matlab

MATLAB emulation package

v1.0.2
Artistic-2.0
Authors
P. Roebuck
Initial release
2014-06-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.