Skip to main content

11.10) for...end Statement: Examples (cont'd)


[matlab]
>> % smoothing of an image using 3x3 averaging filter
>> m=100;
>> n=100;
>> data=rand(m,n);
>> submatrix=zeros(3,3);
>> output=zeros(m,n);
>> for i=2:m-1
>> for j=2:n-1
>> submatrix=data(i-1:i+1,j-1:j+1);
>> output(i,j)=mean(submatrix(:));
>> end
>> end
[/matlab]

Why do the for loops run from 2:m-1 and 2:n-1?