Expand Matrix

Package: kwave.toolbox

Enlarge a matrix by extending the edge values.

Syntax

matrixExpanded = expandMatrix(matrix, expansionSize)
matrixExpanded = expandMatrix(matrix, expansionSize, expansionValue)

Description

expandMatrix enlarges a matrix by extension of the values at the outer faces (endpoints in 1D, outer edges in 2D, outer surfaces in 3D). The edge values are extended by expansionSize, which can be given as a scalar used by all dimension, or as a vector specifying the expansion size in each Cartesian direction. If an input for expansionValue is given, all expanded matrix elements will have this value.

Examples

matrix = magic(3)
matrix =
     8     1     6
     3     5     7
     4     9     2
kwave.toolbox.expandMatrix(matrix, 1)
ans =
     8     8     1     6     6
     8     8     1     6     6
     3     3     5     7     7
     4     4     9     2     2
     4     4     9     2     2
kwave.toolbox.expandMatrix(matrix, [2 0 1 0], 0)
ans =
     0     0     0     0
     0     0     0     0
     0     8     1     6
     0     3     5     7
     0     4     9     2

Input Arguments

  • matrix - (numeric) A 1D, 2D, or 3D matrix to expand.
  • expansionSize - (integer) The expansion size. There are several ways to specify the size. If a scalar value is given, this expansion is added to all sides of the matrix. In 1D, the expansion size at each end can also be specified as [xStartExp, xEndExp]. In 2D and 3D, the expansion size in each Cartesian direction can be specified as [xExp, yExp] or [xExp, yExp, zExp], or for each side in each Cartesian direction as [xStartExp, xEndExp, yStartExp, yEndExp] or [xStartExp, xEndExp, yStartExp, yEndExp, zStartExp, zEndExp].
  • expansionValue - (numeric) Scalar value to use in the matrix expansion.

Output Arguments

  • matrixExpanded - (numeric) Expanded matrix.