If it genuinely happens at the point of calling s= size(img);
, then you probably have a variable size
in your workspace which is shadowing the size
function.
In addition, there are a couple of possible issues with your loop. First, you can't use zero as in index in MATLAB. Hence, when you have i = 1, j = 1
at the start of your loop, you would expect the temp
line to return the Subscript indices error.
the output of size
, presuming img
is a greyscale image, is going to be two numbers. When you do i = 1:s
, it will ignore the second one. This is fine so long as your image is square but will not do what you expect if it isn't.
Finally, have a look at conv2
for cases like this rather than creating a loop.