As its name says it, Matlab if much more efficient if you use matrix-like operations instead of low level For loops. It is very powerful if used in the "Matlab way" so I suggest you check the attached primer guide (around page 47).
As previously mentioned, avoiding loops in Matlab, if possible, is much better.
Using the built in function sum will make life easier. In your example the input is a vector and this will require one loop and this will be definitely increased to two and three in case of 2D and 3D matrices.
To speed up and write a compact code, you may use the following code:
It is great to know that you solved it. However, I guess, all here misunderstood your question as it seemed that you want to calculate the sum which is different from accumulative sum.