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.


2-D convolution matrix


T = convmtx2(H,m,n)
T = convmtx2(H,[m n])



T = convmtx2(H,m,n) returns the convolution matrix T for the matrix H. If X is an m-by-n matrix, then reshape(T*X(:),size(H)+[m n]-1) is the same as conv2(X,H).

T = convmtx2(H,[m n]) returns the convolution matrix, where the dimensions m and n are a two-element vector.


collapse all

Create an averaging filter.

H = ones(3,3)/9; % averaging filter 3-by-3
M = 5;
X = magic(M);
T = convmtx2(H,M,M);
Y1 = reshape(T*X(:), size(H)+[5 5]-1)
Y2 = conv2(X,H)
isequal(Y1,Y2) % They are the same.

Input Arguments

collapse all

Input matrix, specified as a numeric array.

Data Types: double

Rows in convolution matrix, specified as a numeric scalar.

Data Types: double

Columns in convolution matrix, specified as a numeric scalar.

Data Types: double

Dimensions of convolution matrix, specified as a two-element vector of the form [m n], where m is the number of rows and n is the number of columns.

Data Types: double

Output Arguments

collapse all

Convolution matrix, returned as a numeric array. The output matrix T is of class sparse. The number of nonzero elements in T is no larger than prod(size(H))*m*n.

See Also


Introduced before R2006a

Was this topic helpful?