필터 지우기
필터 지우기

for loop with factorial as an increment

조회 수: 2 (최근 30일)
steve guy
steve guy 2013년 2월 21일
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.

채택된 답변

Shashank Prasanna
Shashank Prasanna 2013년 2월 21일
The moment factorial is evaluated, MATLAB just treats it like a number. Which means it would be your first option.
  댓글 수: 3
Shashank Prasanna
Shashank Prasanna 2013년 2월 22일
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 2013년 2월 22일
so if I wanted those to be incremented by two would loopvar=factorial(1:2:n) be correct?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by