Image Processing Toolbox User's Guide Previous page   Next Page
padarray

Pad an array

Syntax

Description

B = padarray(A,padsize) pads array A with 0's (zeros). padsize is a vector of positive integers that specifies both the amount of padding to add and the dimension along which to add it. The value of an element in the vector specifies the amount of padding to add. The order of the element in the vector specifies the dimension along which to add the padding.

For example, a padsize value of [2 3] means add 2 elements of padding along the first dimension and 3 elements of padding along the second dimension. By default, paddarray adds padding before the first element and after the last element along the specified dimension.

B = padarray(A,padsize,padval) pads array A where padval specifies the value to use as the pad value. padarray uses the value 0 (zero) as the default. padval can be a scalar that specifies the pad value directly or one of the following text strings that specifies the method padarray uses to determine the values of the elements added as padding.

Value
Meaning
'circular'
Pad with circular repetition of elements within the dimension.
'replicate'
Pad by repeating border elements of array.
'symmetric'
Pad array with mirror reflections of itself.

B = padarray(A,padsize,padval,direction) pads A in the direction specified by the string direction. direction can be one of the following strings. The default value is enclosed in braces ({}).

Value
Meaning
{'both'}
Pads before the first element and after the last array element along each dimension. This is the default.
'post'
Pad after the last array element along each dimension.
'pre'
Pad before the first array element along each dimension.

Class Support

When padding with a constant value, A can be numeric or logical. When padding using the 'circular', 'replicate', or 'symmetric' methods, A can be of any class. B is of the same class as A.

Example

Example 1

Add three elements of padding to the beginning of a vector. The padding elements, indicated by the gray shading, contain mirror copies of the array elements.

Example 2

Add three elements of padding to the end of the first dimension of the array and two elements of padding to the end of the second dimension. The example uses the value of the last array element as the padding value.

Example 3

Add three elements of padding to the vertical and horizontal dimensions of a three-dimensional array. Use default values for the pad value and direction.

See Also

circshift, imfilter


Previous page  otf2psf para2fan Next page

© 1994-2005 The MathWorks, Inc.