How can I create a for loop that takes the number 500 and multiplies it by 1.1 every 7 steps (7,14,21,...), meaning that i want the answer as follows: 500.... 500*1.1...​.500*1.1*1​.1....500*​1.1*1.1*1.​1 etc

How can I create a for loop that takes the number 500 and multiplies it by 1.1 every 7 steps (7,14,21,...), meaning that i want the answer as follows: 500.... 500*1.1....500*1.1*1.1....500*1.1*1.1*1.1 etc

Más respuestas (1)

Here's a start
a = 500;
k = 1.1;
p = 0:5;
s = 7;
x = a*k.^p;
x = repelem(x,s)
just adjust p as needed to get the desired length.

5 comentarios

It says "Undefined function 'repelem' for input arguments of type 'double'"
repelem() has been builtin since R2015a, so I guess you're running an older version. You can do the same thing without it.
x = reshape(repmat(x,[s 1]),[],1).'
Plus, she asked specifically for a "for loop" though I'm not sure that is mandatory.
DGM
DGM el 15 de Mayo de 2021
Editada: DGM el 15 de Mayo de 2021
I'm beginning to take "how can i make a for loop to do x" questions as simply "how can i do x? i'm thinking of using a bunch of loops, please stop me". OP is free to clarify that loops are necessary.
The for loop is not mandatory... But for the problem I have I should do this for 210 years every 7 years... And the answer I get from each 7 should be added together for the purpose of my question.. I haven't been specific with the question itself since it has lots of equations and calculations to do... The for loop would serve the best at what I'm trying to do :)

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 15 de Mayo de 2021

Comentada:

el 16 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by