Looping with unequal increment

I have x= 5,15,25,30,45,60,65,70,75,90
other parameters (in the body of loop) depends on x values above
I have to run a loop
for i=min(x) : B :max(x)
Body
endfor
What shall be the B? How to go about it?

1 Comment

Note that you should not use i or j for your loop variable names, as these are the names of the inbuilt imaginary unit .

Sign in to comment.

 Accepted Answer

Roger Stafford
Roger Stafford on 21 Jan 2015
Edited: Roger Stafford on 21 Jan 2015
x = [5,15,25,30,45,60,65,70,75,90];
for i = 1:length(x)
% Get parameter values from x(i) and store them at i-th array positions
end

4 Comments

Thanks Sir for the help. I shall surely get back to you.
Note that you should not use i or j for your loop variable names, as these are the names of the inbuilt imaginary unit .
Good point, Stephen. I carelessly used 'i' here just because "i-th" is easier to pronounce than, say, "ix-th".
I'll admit, I like i as a loop variable. It is a throwback to my Fortran days, when i was the variable of choice for loops.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!