how to avoid 'index exceeds matrix dimension' error?
1 view (last 30 days)
Show older comments
filter=[0.25 0.5 0.5 0.5 0.25;0.5 0.75 1 0.75 0.5;0.5 1 2 1 0.5;0.5 0.75 1 0.75 0.5;0.25 0.5 0.5 0.5 0.25];
for i=1:5 for j=1:5 filter(i,j)=filter(i,j)/16; end end
% Performs Smoothing
for v = 3 : m for u = 3 : n sum = 0; for i = -2 : 2 for j = -2 : 2 sum = sum + (I(u+i, v+j) * filter(i+3, j+3)); %here error occurs end end IDx(u,v) = sum; end end
0 Comments
Answers (1)
dpb
on 12 May 2014
filter=[0.25 0.5 0.5 0.5 0.25; ...
...
0.25 0.5 0.5 0.5 0.25]/16;
% Performs Smoothing
for v= 3:m
for u=3:n
sum = 0;
for i = -2 : 2
for j = -2 : 2
sum=sum+(I(u+i,v+j)*filter(i+3, j+3)); %here error occurs
end
end
IDx(u,v) = sum;
end
end
It's not in the filter subscripting so you've blown it w/ I
Having not provided any information for it or m, n, a precise answer isn't possible.
I'd suggest
doc filter2
3 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!