Create a loop with decrementing step
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dennis M
el 25 de Ag. de 2021
Comentada: Dennis M
el 2 de Sept. de 2021
Good Day, May I ask a question, how can I create loop that the output is like this (10 20 29 38 47 56 65 and so on) and (80 70 61 53 46 40 35 and so on) same in negative (-10 -20 -29 -38 -47 -56 -65 and so on) and (-80 -70 -61 -53 -46 -40 -35 and so on)
Thanks
0 comentarios
Respuesta aceptada
the cyclist
el 25 de Ag. de 2021
Do you mean that you want the increment to be 10, 9, 8, ...? (That is not what your first example does). Here is one way to do a series like that. I hope you can generalize to what you need.
inc = 10:-1:1;
step = cumsum(inc)
6 comentarios
the cyclist
el 27 de Ag. de 2021
I would suggest that you really try to understand my other solution. If you did, then it is trivial how to figure out this question.
inc = -10:1:1;
step = cumsum([80 inc])
I suggest you study the MATLAB Onramp online tutorial. You will learn how to do simple tasks like this one.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!