On each loop iteration the loop iterator variable R_e is scalar (i.e. it has size 1x1). Inside the function you define i=1 and then try to access R_e(i+1), i.e. you are trying to access the second element of an array which only contains one element. This is an error.
I do not know how to fix this because you code does not make much sense to me: in partcular those for loops are vey confusing: you should probably be looping over indices, rather than over values. Looping over indices would also resolve the next question you would ask on this forum, about why the loop only stores the last value that you calculate and discards the rest (hint. you need to use indexing on the output array too).
How to use a loop (with indexing to store the output values) is shown in the introductory tutorials, which are highly recommended for learning basic MATLAB concepts: