for loop, in irregular numbers clusters?
Show older comments
i have to make a loop code, but the loopcounter (numbers) very irregular.
for an example: 1 2 3 4 6 7 8 10 12 13 14 15 16 18 19 20.
if i do it in bash script, the code would be like : [for idx in {1..8} 10 {12..16} {18..20}; do echo $idx; done;]
is there good way to code this case with matlab?
(above line is just for an example. in my practical job, the loop counter would go up to thousands.)
please share some wisdom. thank you.
p.s. : actually, in above example, when i loop from 1 to 20, there is a list of numbers "not to do" like [5, 9, 11, 17].
maybe i should make a array [1 ... 20] and delete out "not to do numbers" (5,9, 11,17) from loop...? i don't know how;;
Accepted Answer
More Answers (1)
v = [1 2 3 4 6 7 8 10 12 13 14 15 16 18 19 20];
for k = v
disp("Now serving order #" + k)
end
1 Comment
Jong Yeon
on 20 Oct 2022
Categories
Find more on Loops and Conditional Statements 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!