Create a loop with decrementing step
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
the cyclist
on 25 Aug 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 Comments
the cyclist
on 27 Aug 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.
More Answers (0)
See Also
Categories
Find more on Stress and Strain in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!