Matlab's for-loop is designed so that you cannot change its index, in this case, 'i', within the loop. Even though you have set it to 300, it will stubbornly return on the next trip with i = 41, not 300. To do what you indicate here you should do this instead:
for i = [1:39,300:500]
pause, etc ...
end
If a change in indexing cannot be predicted in advance of entering a for-loop you should use the 'while-end' construct instead where you must control the index yourself instead of an automatic advance at each step. Either that or if you want to sudden depart ahead of time from a for-loop, use the 'break' function.
1 Comment
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/89840-change-for-loop-iteration-inside-the-loop#comment_372930
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/89840-change-for-loop-iteration-inside-the-loop#comment_372930
Sign in to comment.