convmtx2
2-D convolution matrix
Description
Examples
Create a Convolution Matrix
Show that, for 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)
Description of first code block
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)
Y1 = 7×7
1.8889 4.5556 4.6667 3.6667 2.6667 2.5556 1.6667
4.4444 7.6667 8.5556 6.5556 6.7778 5.8889 3.4444
4.8889 8.7778 11.1111 10.8889 12.8889 10.5556 5.8889
4.1111 6.6667 11.0000 13.0000 15.0000 10.6667 4.5556
2.7778 6.7778 13.1111 15.1111 14.8889 8.5556 3.7778
2.3333 5.6667 10.5556 10.7778 8.7778 3.8889 1.3333
1.2222 3.2222 6.0000 5.0000 4.0000 1.2222 1.0000
Y2 = conv2(X,H)
Y2 = 7×7
1.8889 4.5556 4.6667 3.6667 2.6667 2.5556 1.6667
4.4444 7.6667 8.5556 6.5556 6.7778 5.8889 3.4444
4.8889 8.7778 11.1111 10.8889 12.8889 10.5556 5.8889
4.1111 6.6667 11.0000 13.0000 15.0000 10.6667 4.5556
2.7778 6.7778 13.1111 15.1111 14.8889 8.5556 3.7778
2.3333 5.6667 10.5556 10.7778 8.7778 3.8889 1.3333
1.2222 3.2222 6.0000 5.0000 4.0000 1.2222 1.0000
isequal(Y1,Y2) % They are the same.
ans = logical
0
Input Arguments
H
— Input matrix
numeric array
Input matrix, specified as a numeric array.
Data Types: double
m
— Rows in convolution matrix
numeric scalar
Rows in convolution matrix, specified as a numeric scalar.
Data Types: double
n
— Columns in convolution matrix
numeric scalar
Columns in convolution matrix, specified as a numeric scalar.
Data Types: double
[m n]
— Dimensions of convolution matrix
numeric scalar
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
T
— Convolution matrix
numeric array
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
.
Version History
Introduced before R2006a
Ouvrir l'exemple
Vous possédez une version modifiée de cet exemple. Souhaitez-vous ouvrir cet exemple avec vos modifications ?
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)