This line will slow it down a lot:
It resizes YY! on each iteration. Instead, rpeallocate YY1 and then fill it in:
then
Of course if you don't need YY1 for anything other than the sum, then just add it on each iteration:
Also, your function is not dependent on the for loop variables, so the same answer will be returned on each iteration. This you could also just multiple
sum2 = sum(fx*sum(fy))*100*jj
Best Answer