Looping with unequal increment
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2015-1-21
Note that you should not use i or j for your loop variable names, as these are the names of the inbuilt imaginary unit .
采纳的回答
Roger Stafford
2015-1-21
编辑:Roger Stafford
2015-1-21
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 个评论
Roger Stafford
2015-1-21
Good point, Stephen. I carelessly used 'i' here just because "i-th" is easier to pronounce than, say, "ix-th".
John D'Errico
2015-1-21
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 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!