how to write a loop with variable limits

Hi All
I want to write a for loop like :
for j=a:b
bla bla
end
but I need another loop above this , that check a condition ,and if that condition like(c > 0) is not satisfied , add a certain amount to a and b in a way that , if the first time a=1 and b = 100 , the next one will be : a= 101 and b= 200 and then next one be : a= 201 and b= 300 , and when the condition is satisfied , MATLAB exits the loop add a quantity

 채택된 답변

per isakson
per isakson 2015년 3월 18일
편집: per isakson 2015년 3월 18일

1 개 추천

Hint:
while condition == false
if not(c>0)
a = a + something;
b = b + something;
end
for jj = a : b
bla bla
end
end

댓글 수: 3

farzad
farzad 2015년 3월 18일
thank you very much
just one thing , what do I write for condition ? or exactly like that ?
while condition == false
Depends on what you want to achieve. I don't fully understand your question. My hint is kind of pseudo code. Another try:
while not(c>0)
a = a + something;
b = b + something;
for jj = a : b
bla bla
end
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 3월 18일

댓글:

2015년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by