Now it takes even longer i.e., ~1 minute

Does this make sense. Also I am running this loop only once. I do not 
understand why writing in the function form would help. I read the manual 
but they suggest writing function form for something which is used many 
times.
I=runave(S,A,f)
showim(I);

function runave(S,A,f)
  imsz=size(A);
  p1=f+1;
  for n=(f+1):(imsz[2]-f-1)
    for m=(f+1):(imsz[1]-f)
      
S[m,n+1]=S[m,n]+sum(sum(A[m-f:m+f,n+p1],2))-sum(sum(A[m-f:m+f,n-f],2));
    end
  end
  S;
end

Do I have to declare function parameters to speed it up.

Reply via email to