Is there any way to use a for-loop in MATLAB with a custom step? What I want to do is iterate over all powers of 2 lesser than a given number. The equivalent loop in C++ (for example) would be:
for (int i = 1; i < 65; i *= 2)
Note 1: This is the kind of iteration that best fits for-loops, so I’d like to not use while-loops.
Note 2: I’m actually using Octave, not MATLAB.
Perhaps you want something along the lines of
Except you will need to figure out the range of exponents. This uses the fact that since
a_(i+1) = a_i*2this can be rewritten asa_i = 2^i.Otherwise you could do something like the following