Skip to content

Stack Function

stack(...) returns a vector or matrix formed by placing its arguments top to bottom. The arguments must be arrays with the same number of columns, or they must be scalars and column vectors.

For scalar values, stack() returns a column vector containing the list of arguments.

stack() with scalar arguments

In the next example, three column vectors, a, b, and c, are passed as arguments to stack().

stack() with column vector arguments

To obtain a matrix, the vectors must be in row form. Here, the three row vectors d, f, and g are passed as arguments to stack().

stack() with row vector arguments

Row vectors can easily be turned into columns in the matrix by applying a matrix transpose to stack().

stack() combined with a matrix transpose

See also

This page is based on a legacy wiki article by Edward Ulle.