I am confused why the if statement below is not working, I am getting the error message "Array indices must be positive integers or logical values.". Since 1:numel(A) is positive integers, starting at 1, I don't understand where this is coming from, I thought this if statement would filter out to ensure only valid matrix elements are included.
"Error in blur (line 12)
b(i)=A(i-a)"
(for context this is part of code I need for a bigger function I am writing)
E.g tested with A=[ 10 12 7 3 12; 3 10 6 2 8; 18 24 17 6 10; 15 21 10 8 12; 1 18 22 4 15] and w=2.
Many thanks for your help !
function[output]=blur(A,w)
for i=1:numel(A)
for a=0:w
if (1<=(i + a)<=numel(A))&&(1<=(i - a)<=numel(A))
c(i)= A(i+a)
b(i)=A(i-a)
end
end
end
2 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/660228-if-statement-numel-a#comment_1157958
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/660228-if-statement-numel-a#comment_1157958
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/660228-if-statement-numel-a#comment_1158033
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/660228-if-statement-numel-a#comment_1158033
Sign in to comment.