Main Content

Pad or Truncate Matrix with Constant Values

This example shows how to pad or truncate constant values from a matrix using the Pad block.

Open and run the model.

Pad over Rows at the Beginning

When you specify Pad over to Rows and Pad signal at to Beginning, the block pads the matrix rows with the value specified in Pad value. The number of values padded to each row is determined by the Row size parameter. In the first Pad block, the Row size parameter is set to 6.

Pad over Rows and Columns at the Beginning and at the End

When you specify Pad over to Columns and rows and Pad signal at to Beginning and end, the block pads the matrix rows and columns with the value specified in Pad value. The number of values padded to each row and column is determined by the Row size and the Column size parameters. In the second Pad block, the Row size and the Column size parameters are set to 6, respectively.

Truncate over Rows at the End

You can also truncate the matrix by specifying the size of a specific dimension in the output to be less than that of the input. In the third block, Pad over is set to to Rows and the output Row size parameter is set to 2. With this setting, the block truncates the 3-by-3 input matrix over the Rows dimension and makes it a 3-by-2 matrix.

See Also

Blocks