You are defining a variable named sum here
and then later you try to index that variable by a vector of non-integers. It's like doing this:
v([310.15324, 235.3463, 501.346])
If you're trying to use the sum() function, you'll need to use a different variable name.