필터 지우기
필터 지우기

bidirection "FOR" loop counter

조회 수: 1 (최근 30일)
Fatma Abdullah
Fatma Abdullah 2017년 7월 22일
답변: Walter Roberson 2017년 7월 22일
Is there a way to make a FOR loop count in both ways positive and negative?!!.....the counter direction would be specified according to some condition for example:
l1=max(0,(i2-L));
b1=min(i2,(N/2-L));
for j1=l1:b1
In general; i want to give values for 'L' from 0 to 32, this will make l1>b1 for L from 0 to 16 and l1<b1 for L from 16 to 32
  댓글 수: 1
Image Analyst
Image Analyst 2017년 7월 22일
You can set
L = 0:32
but I don't know what i2 is, or what N is, or what values you expect j1 to take on. Please define those variables.

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 22일
l1 = max(0,(i2-L));
b1 = min(i2,(N/2-L));
step = (l1 <= b1) * 2 - 1; %-1 if the condition is false, +1 if the condition is true
for j1 = l1 : step : b1
...
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by