Code generation for `sum` function in MATLAB
Because the size of y1(j1:k1) and y2(j2:k2) must be the same then:
$$
k_1-j_1 = k_2-j_2
$$
and you will also have something like: $j_1+N=j_2$ then you could write a for loop like this:

xc(i) = 0
for n=j1:k1
  xc(i) = xc(i) + y1(n)*y2(n+N)
end