Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nonlinear for loop

Tags:

matlab

Is there a way to create something like a for loop in MATLAB with a nonlinear interval i.e. log scale? I know that I can just use a while loop, but I was wondering if there was something simple like a for loop.

like image 296
Brian Avatar asked Dec 28 '10 10:12

Brian


1 Answers

Is this what you're looking for:

for ctr = logspace(1,10,100)
    disp(ctr)
end

The for loop variable can range over any array. You could do:

x = [1 2 4 4 3 10];
for ctr = x
    disp(ctr)
end

as well.

like image 111
mtrw Avatar answered Nov 10 '22 11:11

mtrw