for loop with factorial as an increment

When you increment a for loop by factorial(n) is matlab updating n within the factorial or is it simply calculating the factorial value and using that as an increment.
ex.
does
factorial(1):factorial(2):factorial(n)
go 1 3 5 7 9 11....n since factorial(2)=2*1
or 1! 3! 5! 7! 9! 11!.....n!
I would test this myself but I do not have software at my disposal.

 Réponse acceptée

Shashank Prasanna
Shashank Prasanna le 21 Fév 2013

0 votes

The moment factorial is evaluated, MATLAB just treats it like a number. Which means it would be your first option.

3 commentaires

steve guy
steve guy le 21 Fév 2013
thank you. do you know how I can make it like the second option?
You can simply do:
loopvar = factorial(1:n)
for i = loopvar
% do something
end
loopvar will have the vector of factorials. In MATLAB you can simple use this variable in the loop as above
steve guy
steve guy le 22 Fév 2013
so if I wanted those to be incremented by two would loopvar=factorial(1:2:n) be correct?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by