MATLAB: System implementation for loop

equationfor loopiterationsystem

Hi, how can I set up this kind of system? My X vector has 84 elements, I want to implement this system :
z1 = 100 + X(1);
z2 = z1 + X(2);
z3 = z2 + X(3);
z4 = z3 + X(4);
etc…for 84 elemens
thanks in advance

Best Answer

Don't create a list of 84 distinct numbered variables. This is a bad idea, terribly poor programming style. It willl create buggy code, and slow code if you try to use those variables.
However, it is trivial to create a new vector with that property.
z = cumsum(X);
z(1) = z(1) + 100;