How can ı set initial value about for statement ???
이전 댓글 표시
Hi !
for i = initial value(normally 1):1:100
for y = 1 : 1: 100
% I calculate something in this for and I understand that I m not in true way.
% And I want to change initial value of my first for loop. Because I dont want to continue
% from the last i. for example last i is 22, and I want to change it with 50.
% How can I change it in loop. ???
end
end
채택된 답변
추가 답변 (3개)
Adam
2014년 8월 6일
0 개 추천
You can use a pre-defined array with a for loop.
e.g.
myArray = 22:100
for i = myArray ... end
You can't change the value of i within a for loop to skip from e.g. 22 upto 50 though all within the same for loop run as far as I am aware
댓글 수: 1
dpb
2014년 8월 6일
Well, you can simulate such, though...which is another alternative (and something similar to which I'm guessing is what OP did given her comment on my earlier Answer) --
myArray = 22:100
for i = myArray
mySkipVal1=37; % some (possibly computed) points at which to skip
mySkipVal2=43;
if iswithin(i,mySkipVal1,mySkipVal2),break,end
...
end
Utility function iswithin is
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
Ben11
2014년 8월 6일
Maybe with something like this:
for k = 1:100
% add your code
if k== 20 % add you condition here
disp('condition violated!')
k = 50
end
end
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!