System implementation for loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
salvatore cancemi
le 5 Mai 2019
Commenté : 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
0 commentaires
Réponse acceptée
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;
Plus de réponses (0)
Voir également
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!