System implementation for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
salvatore cancemi
am 5 Mai 2019
Kommentiert: salvatore cancemi
am 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 Kommentare
Akzeptierte Antwort
John D'Errico
am 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;
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!