Convolution (Matrix Multiplication)
8 次查看(过去 30 天)
显示 更早的评论
How I want to mutliply one matrix in such way that, For eg,
Given a 5x5 Matrix,

And another 3x3 Matrix,

Mutiply this 3x3 Matrix with 5x5 Matrix such that our resultant matrix look as
Resultant Matrix :
Such That Value of a1 = 31(-1) + 41(-1) + 61(-1) + 71(0) + 41(0) + 71(0) + 71(1) + 61(1) + 41(1) = 40

Value of a2 = 41(-1) + 61(-1) + 71(-1) + 41(0) + 71(0) + 81(0) + 61(1) + 41(1) + 91(1) = 20

Value of a3 = 61(-1) + 71(-1) + 41(-1) + 71(0) + 81(0) + 41(0) + 41(1) + 91(1) + 31(1) = -10

Value of b1 = 71(-1) + 41(-1) + 71(-1) + 71(0) + 61(0) + 41(0) + 31(1) + 31(1) + 51(1) = -70

Similarily we can find all elements of Resultant Matrix
So, Our Resultant Matrix is:

Please help with MATLAB Code of a general case that is valid for all dimensions of both the Matrix.
For e.g., If our given matrix is of 5x5, and our multiplying matrix is of 4x4, then our resultant would become 2x2
Another example, If our given matrix is 6x6, and our multiplying matrix is of 3x3, then our resultant would become 4x4.
0 个评论
回答(2 个)
Image Analyst
2021-5-24
编辑:Image Analyst
2021-5-24
Try conv2()
output = conv2(m1, m2, 'valid');
Your demo is either showing correlation (not convolution) or else it's showing you happens after the kernel is already flipped. If you're not getting what you want then try imfilter()
output = imfilter(m1, m2, 'valid');
or try to flip the kernel
output conv2(m1, flipud(fliplr(m2)), 'valid');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Algebra 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!