MATLAB: Bidirection “FOR” loop counter

for loop

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

Best Answer

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