MATLAB Answers

Increment change For loop

22 views (last 30 days)
Amir Ehsani
Amir Ehsani on 24 Sep 2020 at 16:09
Answered: KSSV on 24 Sep 2020 at 16:32
Hello,
I want to gradually increase a FOR loop increment during a program.
For example:
for i=1:2:200
after 10 steps I want the step size increases automatically to 4
Thanks in advance

  0 Comments

Sign in to comment.

Accepted Answer

David Hill
David Hill on 24 Sep 2020 at 16:14
for i=[1:2:19,23:4:200]
end

  0 Comments

Sign in to comment.

More Answers (1)

KSSV
KSSV on 24 Sep 2020 at 16:32
val = [1:2:19,23:4:200] ;
N = length(val) ;
iwant = zeros(1,N) ;
for i = 1:N
iwant(i) = val(i) % In case you want to store some result out of it
end

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by