Clear Filters
Clear Filters

multiplying a weight mask with input matrix

2 views (last 30 days)
Hi, i am trying to find a way to calculate sum(w(i,j)*A(m+i,n+j)) where w is a 3x3 weight mask , A is the input matrix,m & n size of A,i & j size of w. i have written a function to do this.
if true
% code
function Y = myfun (m,n)
A=imread('');
c=0;
for i=1:3
for j =1:3
c=c+A(m+i,n+j)*B(i,j);
end
end
Y=c;
end
end
and a loop to store the values in a matrix C .
if true
% code
[x,y]=size(A);
for m=1:x
for n=1:y
C(m,n)=myfun(m,n);
end
end
end
But i am getting an index out of bound error. i have considered padding the input matrix but it will change the parameters being passed. Please help me solve this.

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 31 Oct 2014
use conv2 function
That will get the job done much faster.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!