System implementation for loop

1 vue (au cours des 30 derniers jours)
salvatore cancemi
salvatore cancemi le 5 Mai 2019
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

Réponse acceptée

John D'Errico
John D'Errico le 5 Mai 2019
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;
  1 commentaire
salvatore cancemi
salvatore cancemi le 5 Mai 2019
Thanks a lot!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by