It won't work correctly for n greater than 10. :-)
ans-7*(ans>10) would fix that.
You are right, you could use ind2sub to avoid some of the limitations of dec2base as well (e.g. for n>36)...
Sum all integers from 1 to 2^n
8423 Solvers
Numbers with prime factors 2, 3 and 5.
166 Solvers
246 Solvers
406 Solvers
5473 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!