Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

padarray

Syntax

B = padarray(A,padsize)
B = padarray(A,padsize,padval)
B = padarray(A,padsize,method)
B = padarray(___,direction)
gpuarrayB = padarray(gpuarrayA,___)

Description

example

B = padarray(A,padsize) pads array A with 0's (zeros). padsize is a vector of nonnegative 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.

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.

B = padarray(A,padsize,method)pads array A where method specifies the method padarray uses to determine the values of the elements added as padding.

B = padarray(___,direction)pads A in the direction specified by the direction.

gpuarrayB = padarray(gpuarrayA,___)performs the padding operation on a GPU, where gpuarrayA is a gpuArray object that contains the image A. The return value gpuarrayB is also a gpuArray. This syntax requires the Parallel Computing Toolbox™.

Examples

collapse all

Pad the Beginning of a Vector

Add three elements of padding to the beginning of a vector. The padding elements contain mirror copies of the array.

A = [ 1 2 3 4 ]
A = 

     1     2     3     4

B = padarray(A,3,'symmetric','pre')
B = 

     1     2     3     4
     1     2     3     4
     1     2     3     4
     1     2     3     4

Pad Each Dimension of a 2-D Array

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. Use the value of the last array element on each dimension as the padding value.

A = [ 1 2; 3 4 ]
A = 

     1     2
     3     4

B = padarray(A,[3 2],'replicate','post')
B = 

     1     2     2     2
     3     4     4     4
     3     4     4     4
     3     4     4     4
     3     4     4     4

Pad Each Dimension of a 3-D Array

Add three elements of padding to each dimension of a three-dimensional array. Each pad element contains the value 0.

First create the 3-D array.

A = [1 2; 3 4];
B = [5 6; 7 8];
C = cat(3,A,B)
C = 
C(:,:,1) =

     1     2
     3     4


C(:,:,2) =

     5     6
     7     8

Pad the 3-D Array

D = padarray(C,[3 3],0,'both')
D = 
D(:,:,1) =

     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     1     2     0     0     0
     0     0     0     3     4     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0


D(:,:,2) =

     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     5     6     0     0     0
     0     0     0     7     8     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0

Add padding on all sides of an image.

gcam = gpuArray(imread('cameraman.tif'));
padcam = padarray(gcam,[50 50],'both');
imshow(padcam)

Input Arguments

collapse all

Array to be padded, specified as a numeric or logical array. 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.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Amount of padding to add to each dimension, specified as a vector of nonnegative integers. 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.

Data Types: double

Value to use for the padding, specified as a numeric scalar.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

How to pad array, specified as one of the following strings or character vectors:

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.

Example:

Data Types: char | string

Where to pad array along each dimension, specified as one of the following strings or character vectors:

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.

Example:

Data Types: char | string

Image to be padded, specified as a gpuArray.

Example:

Output Arguments

collapse all

Padded array, returned as a numeric array. B is of the same class as A.

Extended Capabilities

Introduced before R2006a

Was this topic helpful?